.env.development Now
The Power of .env.development: Streamlining Your Development Environment
.env.development: A Best Practice for Managing Development Environment Variables .env.development
- Create a
.env.developmentfile: In your project's root directory, create a new file named.env.development. - Add environment variables: Populate the file with environment-specific variables, one per line, in the format
VARIABLE_NAME=VALUE. - Update your code: In your code, access these variables using a library or framework-specific method (e.g.,
process.env.VARIABLE_NAMEin Node.js). - Load the
.env.developmentfile: Use a library or framework that loads the.env.developmentfile automatically, such asdotenvin Node.js.
: In frontend frameworks, these variables are often "inlined" during the build process, meaning they are baked into the JavaScript code. Local Overrides The Power of
const dbConfig = host: process.env.DB_HOST_DEV, port: process.env.DB_PORT_DEV, user: process.env.DB_USERNAME_DEV, password: process.env.DB_PASSWORD_DEV, ;3. Syntax rules
# .env.development
API_URL=http://localhost:3000
DEBUG=true
SECRET_KEY=dev_secret_123 # never reuse production secrets
PORT=4000
It sits quietly in your project root, never committed to version control, rarely celebrated in blog posts or tutorials. Yet, for developers who spend their days wrestling with APIs, databases, and third‑party services, .env.development is an indispensable ally. Create a
file with the keys but no values so other developers know what they need to set up. Common File Structure An example .env.development file might look like this:
# Logging Settings LOG_LEVEL=debug LOG_FORMAT=dev