| File Naming Strategy | Primary Purpose | Should be committed to Git? | Loads for... | | :--- | :--- | :--- | :--- | | | Base configuration, default values for all environments. | No (ideally, often committed as a template .env.example ). | All environments. | | .env.local | Local overrides for your specific machine. | Never. Always add to .gitignore . | All environments. | | .env.development | Settings for the development environment (e.g., local API endpoints). | Yes (as a template). | npm run dev , next dev . | | .env.production | Default settings for the production environment (e.g., live API endpoints). | Yes (as a template). | npm run build , next start . | | .env.development.local | Highest priority overrides specific to your local development environment. | Never. | npm run dev . | | .env.production.local | Highest priority overrides for testing a production build locally. | Never. | npm run build , next start . | | .env.test | Settings for the testing environment. | Yes (as a template). | npm run test . |
| File | Gitignore | Load in dev | Load in prod | Purpose | |--------------------------|-----------|-------------|--------------|---------| | .env | ❌ No | ✅ Yes | ✅ Yes | Defaults | | .env.local | ✅ Yes | ✅ Yes | ❌ No | Local overrides (dev only) | | .env.production | ❌ No | ❌ No | ✅ Yes | Production defaults | | .env.production.local | ✅ Yes | ❌ No | ✅ Yes | |
By placing a staging tracker token inside .env.production.local , your local next start execution will route data safely to a test dashboard. 3. Testing Server-Side Caching and ISR .env.local.production
In next.config.js :
✅ .env.production.local has the highest priority when NODE_ENV=production . | File Naming Strategy | Primary Purpose |
Your .gitignore file should contain: # Environmental variables .env .env.*.local Use code with caution.
require('dotenv').config( path: '.env.production.local' ); | No (ideally, often committed as a template
Do not put application logic inside environment variable files. They are for configuration, not code. The value of an environment variable should be a simple string, number, or boolean. Complex data structures should be serialized (e.g., as JSON strings) if necessary.
This file sits at the top of the environment variable hierarchy. When a project is built or run in , it will prioritize values in this file over standard defaults. Git Status .env Default values for all environments. .env.production Production-specific defaults. .env.local.production Local overrides for production testing. Ignored (Private) Key Characteristics
.env.local.production (or .env.production.local ) is a niche but valid pattern for and machine-specific production overrides . Use it sparingly, never commit it, and prefer cloud secret managers for real production environments.