<strong>Environment variables</strong> are configuration values stored outside your code that change based on where your app runs (development, staging, production). They keep sensitive data like API keys out of your codebase.
The Costume Change Analogy
You're the same person but wear different clothes for different occasions. Your app is the same code but uses different configurations (environment variables) for different environments.
Work Clothes (Production)
Professional settings
Casual Clothes (Development)
Comfortable settings
You (The App)
Same person, different outfit
Reads Variables
Provides Values
Adapts to Environment
Define variables
Create .env file with KEY=value pairs
Load in code
process.env.KEY or similar in your language
Different per environment
Dev uses test DB, production uses real DB
Never commit secrets
Add .env to .gitignore
Set in deployment
Configure on Vercel, Heroku, AWS, etc.
Wrong
"Environment variables are just for API keys"
Correct
Environment variables are for <strong>any configuration that changes per environment</strong>: database URLs, feature flags, debug modes, third-party endpoints, etc.
Typical .env file:
DATABASE_URL=postgres://localhost/dev (dev) vs production URL
API_KEY=test_key (dev) vs live_key (production)
DEBUG=true (dev) vs false (production)
STRIPE_KEY=test_key (dev) vs live_key (production)