.env.local
1. Storing Secrets (API Keys) This is the most common use case. You are building an app that uses Stripe, Google Maps, or OpenAI. You cannot put these keys in the public codebase.
2. Machine-Specific Configuration Not all developers run their databases or services on the same ports. One developer might be running a local Docker instance of PostgreSQL on port 5432, while another might be pointing to a cloud staging database. .env.local
3. Debugging Flags You might want to enable verbose logging or debug mode on your machine without affecting the team’s default configuration. .env.local should not be.
# .env - committed to repo (public-safe)
DATABASE_HOST=localhost
NEXT_PUBLIC_APP_NAME=MyApp
Why isn't my .env.local loading? Here are the top five mistakes. but with some key differences:
It must be exactly .env.local in the root directory. Not env.local, not .env.local.txt, not .envLOCAL.
.env.local is similar to .env, but with some key differences:
While .env is often committed to version control, .env.local should not be.