import environ env = environ.Env() environ.Env.read_env(overwrite=True)
When you run your application in development mode (e.g., npm run dev or npm start ), files are loaded with the following priority (left having highest priority):
Always include an .env.example file in your repository that lists all required environment variables, providing a quick-reference documentation for new team members:
When building or running in production mode, the priority shifts:
The .env.development file is an essential tool for separating configuration from code. By accurately isolating your local settings from your production environment, you mitigate the risk of accidental data corruption, protect sensitive credentials, and build a highly portable application that can run seamlessly on any developer's machine. Combine it with a robust .env.example template, utilize local overrides wisely, and always keep your framework's client-side prefixes in mind for a secure, frictionless development workflow.
.env.development.local → .env.local → .env.development → .env
While .env files are incredibly useful, they come with specific responsibilities.
If you want to optimize your environment setup, let me know:
Proper .gitignore configuration is crucial. The recommended approach is:
For vanilla Node.js applications, the dotenv-flow package extends the standard dotenv to support NODE_ENV -specific files like .env.development and .env.production .
Check the file location. The .env.development file must be in your project's root directory (where you run the command). Also, verify you have restarted the server.
# .env.example # Required variables - copy to .env or .env.development NEXT_PUBLIC_API_BASE=http://localhost:3000/api NEXT_PUBLIC_APP_NAME=Your App Name DB_URL=postgresql://localhost:5432/yourdb AUTH_SECRET=your-secret-here LOG_LEVEL=debug
: In Create React App, only variables prefixed with REACT_APP_ are accessible. Using any other prefix will result in the variable not being available.