[better] — .env.development
# .env.production PAYMENT_GATEWAY=https://api.stripe.com/v1
When you run npm run build , it ignores that file and pulls from .env.production . 2. Team Standardization
If multiple .env files exist, the framework loads them based on a strict hierarchy. File Cascading and Priority
NEXT_PUBLIC_API_BASE_URL="http://localhost:3000/api" VITE_GOOGLE_MAPS_API_KEY="AIzaSyD_...123" REACT_APP_FEATURE_FLAG_NEW_UI="true" .env.development
| File Name | Purpose | Git Status | Load Conditions | |-----------|---------|------------|-----------------| | .env | Global default configuration for all environments | Commit (template values only) | Always loaded | | .env.local | Local overrides for all environments (except test) | (gitignored) | All environments except test | | .env.development | Development-specific defaults | Commit (safe defaults) | Development mode only | | .env.development.local | Local overrides for development only | Ignore (gitignored) | Highest priority in dev | | .env.production | Production-specific defaults | Commit (safe defaults) | Production mode only | | .env.test | Testing-specific configuration | Commit | Test mode only |
Instead of constantly commenting out lines in your .env file to switch between your local host and a live server, the build tool handles it for you. When you run npm start , it pulls from .env.development .
The dotenv-expand package (included with many implementations) will resolve $APP_NAME to "MyDevApp". Most developers use a basic
Most developers use a basic .env file for all their environment variables. However, larger projects use environment-specific files to avoid manual switching.
The following is a sample .env.development file for a typical web development project:
.env.development : A file containing variables specific to local development. rename it to .env.development
New developers can simply duplicate this file, rename it to .env.development , and fill in their local values. 2. Know When to Commit to Git
ENABLE_DEBUG_LOGGING=true ENABLE_MOCK_SERVICES=true SHOW_DEV_TOOLS=true