devvars
DevVars: The Complete Problem-Solver's Guide to Development Variables & Environment Configuration
Key Takeaways
- Devvars (development variables) are environment-specific configuration values that control application behavior without changing source code.
- They bridge the gap between local development, staging, and production — reducing configuration drift and deployment errors.
- Poor devvar management causes security breaches, environment inconsistency, and team onboarding friction.
- Best practice: use typed .env files, a centralized secret manager, and runtime validation to catch misconfigurations early.
- 3 common mistakes to avoid: committing secrets to version control, mixing environments, and skipping type validation on load.
What Are DevVars and Why Do They Exist?
Devvars — short for development variables — are externalized configuration values that an application reads at runtime. They replace hardcoded constants with environment-aware settings, enabling the same codebase to behave differently across local, staging, test, and production environments.
Without devvars, every environment change requires a code deploy. With them, you swap configuration — not code.
Common Types of DevVars
- Database URLs and credentials — connection strings, passwords, hostnames per environment
- API keys and tokens — third-party service credentials (Stripe, Twilio, cloud providers)
- Feature flags — boolean toggles that enable/disable functionality without a release
- Application secrets — JWT signing keys, encryption keys, session cookies
- Behavioral switches — log levels, timeout values, retry counts, cache TTLs
- URL endpoints — base URLs for APIs, CDNs, and auth callbacks that differ per environment
The Core Problems DevVars Solve
Most development teams eventually hit one or more of these pain points. If you recognize any, devvars are the fix.
Problem 1: Hardcoded Secrets in Source Code
When API keys or passwords live inside source files, they get committed to Git, leaked in PRs, and become impossible to rotate without a full redeploy. Devvars separate secrets from code entirely.
Problem 2: Environment Drift
"It works on my machine" usually means configuration has diverged between environments. A missing variable in staging that exists in production causes runtime failures that are expensive and stressful to debug.
Problem 3: Onboarding Friction
New developers spend hours or days trying to replicate environment setup manually. A well-structured devvar system with a sample .env file cuts onboarding from days to minutes.
Problem 4: Manual Deploy-Only Configuration Changes
Without devvars, toggling a feature or updating an endpoint requires building and deploying — slow, risky, and unnecessary.
DevVar Management Approaches Compared
| Approach | Security | Scalability | Team Onboarding | Best For |
|---|---|---|---|---|
| Hardcoded in code | Very Poor | None | N/A | Never |
| .env files (local only) | Good | Small teams | Moderate | Startups, solo devs |
| .env + dotenv libraries | Good | Small to medium | Easy | Most web applications |
| Container environment variables (Docker/K8s) | Very Good | Large scale | Requires documentation | Cloud-native deployments |
| Secrets managers (AWS Secrets Manager, HashiCorp Vault) | Excellent | Enterprise | Medium complexity | Regulated industries, multi-account |
| Configuration-as-code (Terraform, Pulumi) | Excellent | Infrastructure scale | High learning curve | DevOps-heavy teams |
DevVar Implementation Checklist
Use this checklist to audit or build your devvar system from scratch.
- All secrets excluded from version control (.gitignore)
- A
.env.examplefile committed with all required keys documented - Runtime validation on startup (e.g., Zod, Yup, pydantic) rejects missing or malformed vars
- Different .env files per environment (local, staging, production) with clear naming
- Type annotations on every devvar (string, boolean, URL, number)
- CI/CD pipeline injects production vars from a secrets manager — never from code
- Local development includes a setup script that copies .env.example to .env.local
- Logging is suppressed for secret variables; no .env content appears in stdout
- Rotation policy documented for all credentials and API keys
- Feature flags have a runtime fallback value defined for every flag
Frequently Asked Questions
1. Should I commit .env files to version control?
No — never commit sensitive .env files. The standard practice is to commit a .env.example template that lists every variable name and its expected format without real values. Your actual .env or .env.local file should be in .gitignore. This gives the team a clear reference while keeping secrets out of the repository history.
If you need per-environment secrets in CI/CD, inject them through your platform's secret store — GitHub Actions secrets, AWS Parameter Store, or similar — rather than relying on file-based configs.
2. How do I prevent environment drift between local, staging, and production?
Environment drift happens when the shape of your devvars diverges across environments. The most effective fixes are:
- Shared schema validation: Define a single schema (e.g., a Zod or Pydantic model) that all environments must satisfy at startup. If a required variable is missing or typed incorrectly, the app refuses to launch.
- Automated drift detection: Run a CI check that compares the set of required variables in your schema against what exists in each environment.
- Documentation via code: Keep
.env.exampleauto-generated from the schema so it always stays in sync.
Together, these approaches make drift a build-time failure rather than a surprise in production.
3. What's the difference between devvars and configuration files like JSON or YAML?
Devvars are specifically designed to be runtime-swappable, environment-external, and secret-safe. While JSON or YAML config files can store the same data, they lack three critical properties:
- Shell-level injection: Devvars are typically injected as OS-level environment variables, which containers and orchestration platforms handle natively.
- Secret exposure risk: JSON