.env.local
The data inside a .env.local file is formatted as simple strings without complex data types:
: It allows every developer on a team to have their own unique setup. One person might use a local Docker database, while another connects to a cloud-based staging instance—both can coexist without messy merge conflicts. Ease of Syncing : Platforms like
In almost every framework (especially Next.js), over all other non-specific files. If API_KEY=abc123 is in .env and API_KEY=xyz789 is in .env.local , the application will use xyz789 locally. .env.local
: Always add .env.local to your .gitignore file to prevent it from being committed to your version control system.
Use the KEY=VALUE format. Do not use spaces around the equals sign or quotes (unless the value contains spaces). The data inside a
# Database Configuration DATABASE_URL="postgresql://user:password@localhost:5432/mydb" # API Keys (Sensitive - Keep local only) STRIPE_SECRET_KEY="sk_test_4eC39HqLyjWDarjtT1zdp7dc" NEXT_PUBLIC_ANALYTICS_ID="UA-12345678-1" # Service URLs BACKEND_API_URL="http://localhost:4000/api" # Feature Flags ENABLE_NEW_DASHBOARD=true Use code with caution. Copied to clipboard Key Characteristics
Why isn't my .env.local loading? Here are the top five mistakes. If API_KEY=abc123 is in
Because you explicitly load .env.local second (with override: true ), it overwrites the default .env values.
# .gitignore .env .env.local .env.development.local .env.production.local Use code with caution. The Solution: Using .env.example
Older React apps built with Create React App look for the REACT_APP_ prefix.