Serksa
All Concepts
DevOps & Infrastructure

Environment Variables

1

What is it?

<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.

2

Think of it like...

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

3

Visual Flow

💻Your Code

Reads Variables

🔧Environment

Provides Values

⚙️App Behavior

Adapts to Environment

4

Where you see it

1

Define variables

Create .env file with KEY=value pairs

2

Load in code

process.env.KEY or similar in your language

3

Different per environment

Dev uses test DB, production uses real DB

4

Never commit secrets

Add .env to .gitignore

5

Set in deployment

Configure on Vercel, Heroku, AWS, etc.

5

Common Mistake

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.

💡 Real-World Example

Typical .env file:

1

DATABASE_URL=postgres://localhost/dev (dev) vs production URL

2

API_KEY=test_key (dev) vs live_key (production)

3

DEBUG=true (dev) vs false (production)

4

STRIPE_KEY=test_key (dev) vs live_key (production)