[portable] - .env.development
| Problem | Solution | |---------|----------| | Variables are undefined | Ensure prefix (e.g., REACT_APP_ ) if using a frontend framework | | .env.development ignored in production | Check framework's env file loading rules – most ignore it when NODE_ENV=production | | Changes not applied | Restart the dev server | | dotenv overrides existing process.env | Use override: true (dotenv 16+) |
| Practice | Rationale | |----------|-----------| | Commit .env.development (with safe defaults) | Provides consistent team configuration | | Gitignore .env.local and .env.*.local | Prevents accidental secret commits | | Use prefix conventions ( REACT_APP_ , NEXT_PUBLIC_ , etc.) | Enables framework integration | | Never commit real secrets, even in development | Secrets can be stolen from repos | | Validate required variables at startup | Catches configuration errors early | | Use secret managers in production | More secure than file-based config | | Rotate exposed credentials immediately | Mitigates security breaches | .env.development
.env.development is a simple yet powerful tool for managing environment variables during development. By using a centralized file to store environment-specific variables, developers can improve security, reduce maintenance headaches, and increase flexibility. By following best practices and using .env.development in conjunction with other environment-specific files, developers can streamline their development workflow and focus on building great applications. | Problem | Solution | |---------|----------| | Variables
Or pass variables individually: -e VAR=value . Or pass variables individually: -e VAR=value
commit .env.development to Git. Add it to your .gitignore file immediately.
PORT=8080 LOG_LEVEL=debug
# .env.development # Database configuration DB_HOST=localhost DB_USER=dev_user DB_PASSWORD=secret_password # API endpoints for frontend NEXT_PUBLIC_API_URL=http://localhost:8000/api # Enable debug mode DEBUG=true Use code with caution. 2. Loading Variables in Node.js