By isolating these variables from your core application logic, you ensure that your code remains modular, secure, and easily adaptable across different stages of the software deployment lifecycle.
In Node.js, process.env is mutated at startup. If you change .env.development while the server is running, the app won't see the changes. after editing environment files.
This is a controversial point. You should commit .env.production (it contains secrets). However, .env.development should be committed to your repository because it contains no real secrets—only local URLs, mock keys, and safe defaults. Committing it ensures all developers on your team have the same baseline configuration.
PAYMENT_GATEWAY=http://localhost:9090/mock-stripe .env.development
.env.development is a configuration file used by many development tools and frameworks, including Node.js, React, and Next.js. It's a simple text file that stores environment-specific variables, such as API keys, database connections, and other sensitive data.
When you run npm run build , it ignores that file and pulls from .env.production . 2. Team Standardization
Once you have mastered the basics, you can explore advanced techniques that leverage the full power of .env.development . By isolating these variables from your core application
Stop the server ( Ctrl+C ) and restart it. For Next.js, you may need to run next clean to clear the cache.
.env.development allows you to toggle features like ENABLE_SOURCE_MAPS=true without risking a performance hit in production.
// app.js require('dotenv').config( path: './.env.development' ); after editing environment files
To maximize security and maintainability, follow these best practices:
: Frameworks like Next.js or Create React App automatically load this file when they detect NODE_ENV=development .
: Follow the Unix convention of KEY_NAME=value . Avoid spaces or special characters in the key.
Because .env.development might be committed to the repository (depending on your team’s policy), it should only contain safe-for-public dev defaults.