| File Name | Purpose | Version Control | | ----------------------- | --------------------------------------------------- | --------------- | | .env-development | Local development (defaults, mock services) | Commit (safe) | | .env-production | Real production secrets, API keys, database URLs | | | .env-staging | Pre‑production, mirrors production but with test data | Usually no (or redacted) | | .env-test | Unit/integration testing (in‑memory DB, no external calls) | Commit | | .env-local | Overrides for a specific developer’s machine | Never commit | | .env-ci | Used by GitHub Actions, GitLab CI, Jenkins | No (injected) |
: Shared configuration used by the team during the primary feature-building phase.
Developers can quickly set up a project by creating a .env file without modifying the source code. 3. How to Use .env in Different Languages
const env = process.env.NODE_ENV || 'development'; const envFile = .env-$env ; | File Name | Purpose | Version Control
You never want your local development testing to accidentally modify your live production database. By using .env-development and .env-production , your code automatically points to completely different databases depending on where it is running. 2. Differing Feature Flags and Debugging
find /home -type f ( -name " .env- " -o -name "*.env.bak" )
Are you deploying to a (like Heroku, AWS, or Vercel)? How to Use
The .env file solves this problem. It acts as a standardized, plaintext configuration file used to store sensitive data and environment-specific variables separate from the actual source code. What is a .env File?
: Periodically search your code repositories for leaked .env- configurations using automated secret scanning tools like GitGuardian or GitHub Secret Scanning.
Tools like Vite or Next.js natively detect the running mode. If you run npm run dev , the bundler automatically pulls from the development file. If you run npm run build , it switches to the production parameters without requiring you to manually rewrite any code. Cleaner Codebases Differing Feature Flags and Debugging find /home -type
from dotenv import load_dotenv import os
For better control, use dotenv-expand to interpolate variables, or switch to dotenv-flow which natively supports loading .env-<NODE_ENV> files in order of precedence.
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'development'; $dotenv = Dotenv::createImmutable(, ".env-$env"); $dotenv->load();
Create .git/hooks/pre-commit :