π Environment Management β
Managing dev, staging, and production environments consistently.
Environment types β
| Environment | Purpose | Data | Access |
|---|---|---|---|
| Local/Dev | Individual development | Seed/mock data | Developer |
| Staging | Pre-production testing | Anonymized prod-like | Team |
| Production | Live users | Real data | Restricted |
Environment parity β
Keep environments as similar as possible:
- Same OS, runtime versions, and dependencies
- Same infrastructure (containers, load balancers)
- Same configuration structure (different values)
- Same deployment process
Configuration management β
# .env.example (committed β template)
DATABASE_URL=
REDIS_URL=
API_KEY=
# .env (NOT committed β local values)
DATABASE_URL=postgres://localhost:5432/myapp_dev
REDIS_URL=redis://localhost:6379
API_KEY=dev-key-123Rules β
- Never commit
.envfiles - Commit
.env.exampleas a template - Validate env vars at startup (fail fast if missing)
- Use different secrets per environment
- Store production secrets in a vault, not env files
Feature flags β
Control feature rollout per environment:
typescript
if (featureFlags.isEnabled('new-checkout', { env, userId })) {
// new behavior
}- Enable in staging first, then canary, then production
- Clean up old flags regularly
- Use a feature flag service (LaunchDarkly, Unleash, or DIY)
Database per environment β
- Local: SQLite or Docker container
- Staging: Separate instance with anonymized data
- Production: Managed service with backups
- Never connect local code to production database