.env.development
While .env files are incredibly useful, they come with specific responsibilities.
1. The Golden Rule: Never Commit Secrets
The most critical rule of environment files is that they should never be committed to version control (like Git). A .env.development file often contains sensitive information, such as database passwords or API keys. Even though these are "development" keys, leaking them can still pose a security risk.
You must add .env.development to your .gitignore file. This ensures that your secrets stay on your local machine and are not pushed to GitHub or Bitbucket for the world to see.
2. Use a Template File
Since the actual .env.development file is ignored by Git, how do new team members know what variables to set? The solution is to create a commit-safe template file, usually named .env.development.example. This file contains the keys but dummy or empty values. When a new developer clones the project, they copy the example file, rename it to .env.development, and fill in their actual credentials.
3. Validation
It is good practice to validate that the required environment variables are present when the application starts. If DB_HOST is missing, the app should crash immediately with a clear error message, rather than failing mysteriously later on when it tries to run a query.
PAYMENT_GATEWAY=http://localhost:9090/mock-stripe
If you store production AWS keys in a .env file that you accidentally commit to GitHub, bots will find them within minutes. .env.development is rarely committed (but can be, if it contains only harmless dev defaults). .env.development
The structure is intentionally simple and human-readable. A typical .env.development file might look like this:
# Application Settings
NODE_ENV=development
PORT=3000
# Database Configuration
DB_HOST=localhost
DB_USER=dev_user
DB_PASS=dev_password
# External APIs (Using Test/Sandbox Keys)
SENDGRID_API_KEY=SG.test.fakekey
STRIPE_SECRET_KEY=sk_test_12345
# Feature Flags
ENABLE_NEW_UI=true
Key components:
The .env.development file is deceptively simple. It is just a list of key-value pairs. But its impact on developer productivity, application security, and team collaboration is immense.
To summarize the modern .env.development workflow:
By treating your environment configuration with the same rigor as your application code, you eliminate the dreaded "works on my machine" syndrome. You create a reproducible, predictable, and safe development environment for everyone on your team.
The next time you start a new project, don't leave your team to guess which variables they need. Write the .env.development file first—and watch your onboarding friction disappear. If you store production AWS keys in a
To create the content for a .env.development file, you need to define key-value pairs for settings specific to your local development environment, such as local database URLs or development API keys. Standard Template .env.development
file includes variables for your local server, API endpoints, and authentication keys: # Server Configuration PORT=3000 NODE_ENV=development # API Endpoints (Local/Staging)
API_BASE_URL=http://localhost:5000/api DB_CONNECTION_STRING=mongodb://localhost:27017/my_dev_db # Mock/Test Credentials
STRIPE_PUBLIC_KEY=pk_test_your_key_here FIREBASE_API_KEY=your_dev_firebase_key Use code with caution. Copied to clipboard Framework-Specific Naming Rules Most modern frameworks require a specific
for environment variables to be accessible in the browser. Variables without these prefixes are often ignored to prevent accidental exposure of secrets. : Must start with
The .env.development file is an environment-specific configuration file used to store variables—such as API keys, database URLs, and feature flags—that should only be active during local development. Core Purpose & Usage Key components:
The
Targeted Configuration: While a standard .env file usually contains shared defaults, .env.development is specifically loaded when your development server is running (e.g., via npm start or vite).
Separation of Concerns: It allows you to use a local "sandbox" database or a mock API endpoint without accidentally pointing to production data.
Automatic Loading: Modern frameworks like Vite, Next.js, and Create React App automatically detect and prioritize this file when NODE_ENV is set to development. Essential Best Practices Guides: Environment Variables - Next.js
The primary utility of .env.development is the separation of configuration from code.
Imagine you are building an e-commerce app. In production, you want to connect to your live database and use a live payment gateway (like Stripe). However, while developing, you do not want to charge real credit cards or modify real user data. You want to connect to a local database and use a "sandbox" or "test" API key.
Without .env.development, you might be tempted to hardcode these values or manually comment them in and out of your source code. This is dangerous and inefficient. The .env.development file allows you to define variables like DB_HOST=localhost and STRIPE_KEY=test_key_123 locally. When the code is deployed to production, the build process ignores this file entirely, ensuring that the production environment uses its own secure, live variables.
You can create scripts that modify behavior based on the presence of .env.development.
// package.json
"scripts":
"dev": "node scripts/validate-dev-env.js && NODE_ENV=development nodemon src/index.js"
The validation script checks that required .env.development keys exist before the app starts.