Environment variables are configuration values stored outside your code that change based on the deployment context. They keep secrets like API keys, database URLs, and service credentials separate from source code — preventing accidental exposure and allowing different configurations for development, staging, and production.
Environment variables are the standard way to manage configuration and secrets in modern development. Every vibe-coded project that connects to external services needs them.
Without environment variables:
With environment variables:
# .env file (never committed)
DATABASE_URL=postgresql://localhost:5432/myapp
OPENAI_API_KEY=sk-...
NEXT_PUBLIC_APP_URL=http://localhost:3000
Your code reads these values at runtime instead of using hardcoded strings.
.env — Default environment file.env.local — Local overrides (highest priority).env.example — Template showing required variables (safe to commit)