It's a lot of references to dotenv library to use when you want to specify env variables. But why? I can just specify my var in a file like this:
var dev = { } var prod = { } var config = null; if (process.env.NODE_ENV === 'production') { config = prod } else { config = dev } exports.config = config and assign my var in npm srcipts, like this:
"scripts": { "start": "NODE_ENV=dev node bin/dev", "production": "NODE_ENV=production node bin/production" } Is my way not secure? Why is dotenv way recommended? Why should I create .env files instead my config.js?
.dotEnvisn't secure either. But that's not the point. You should exclude.envfrom your git repo so no one else can inadvertently see your values. Then when you deploy to a server you add it to the environment files of your server.