.env.local ❲HD 4K❳
# .env.local
Prefix with NEXT_PUBLIC_ (e.g., NEXT_PUBLIC_ANALYTICS_ID ) Vite: Prefix with VITE_ (e.g., VITE_APP_TITLE )
Every developer on a team might have a slightly different local setup. One developer might run PostgreSQL on port 5432, while another runs it on port 5433. .env.local allows each team member to customize their setup without conflicting with anyone else's configuration. The Environment File Hierarchy: Where Does .env.local Fit?
: Frameworks use .env.local to override default values set in a shared .env file.
Your .env file often acts as a template (frequently mirrored as .env.example ). If you put your actual, private API keys in .env , you risk accidentally pushing them to GitHub. By using .env.local , you ensure that sensitive credentials stay out of the repository. 3. Environment Specificity .env.local
Mastering .env.local is an essential skill for modern development, directly impacting the security, collaboration, and stability of your projects. It provides a simple, powerful mechanism for you to maintain your own personal workspace while respecting shared project defaults. By strictly following the priority rules and, most importantly, the security best practices outlined here, you will build a development workflow that is both robust and secure.
(or .env.production.local depending on the mode) .env.local .env.development (or .env.production ) .env
If .env.local is ignored by Git, how do other developers know what variables your application needs to run?
The .env.local file is usually placed in the root directory of a project, alongside the .env file. The .local suffix indicates that the file contains local, environment-specific variables that should not be committed to version control. The Environment File Hierarchy: Where Does
Because .env.local is ignored by Git, a new developer cloning your repository won't know what environment variables your application requires to run.
By respecting the file hierarchy and keeping your secrets strictly local, you protect your application, your data, and your users.
DATABASE_URL="postgresql://localhost:5432/mydb" API_SECRET_KEY="super_secret_local_key" NEXT_PUBLIC_ANALYTICS_ID="UA-12345678-1" Use code with caution.
Its core purpose is to separate configuration from code, which has several critical benefits: If you put your actual, private API keys in
The security model of .env.local is based on .
Using different keys for development, staging, and production environments to limit the impact of a potential leak.
Some frameworks allow .env.production.local , but treat this as a nuclear option. Your staging and production servers should read environment variables from the (e.g., export in Linux, or via Docker secrets, Vercel/Koyeb dashboard, or AWS Secrets Manager). File-based envs on production are a security risk and a configuration nightmare.