Reputation: 489
I've been seeing a lot of NodeJS and dotenv
tutorials and articles where they define an ENV_MODE=development
variable within the config.env
file.
But require('express').get('env')
already gives us the environment express is set on running. Why not just use the express env
variable to check the environment mode? Why do we need to also set the explicit variable in the .env
file?
Upvotes: 0
Views: 291
Reputation: 944442
You have to set the environment variable somewhere.
Doing it in a .env
file ties it to a specific computer, which means you don't have to either:
… and it lets you keep it with any other environment variables you have (such as API keys) which shouldn't be committed to version control (since they are secrets).
Upvotes: 2