I am using the 'config' module in my node.js app and I was wondering how to implement environment variables for different environments (dev/prod) based on NODE_ENV.
Say I'm setting the NODE_ENV to production. I have a 'config' folder with 4 JSON files: custom-environment-variables.json, production.json, development.json and default.json.
production.json:
{
"name":"Cost Manager Application - Production",
"db":"prod_db_key"
}
development.json:
{
"name":"Cost Manager Application - Development",
"db":"dev_db_key"
}
default.json:
{
"name":"Cost Manager Application",
"appPrivateKey":"",
"db": "mongodb://localhost:27017"
}
Now, I want to store both my prod and dev db strings in env variables, named prod_db_key and dev_db_key and I know that that's what the custom-environment-variables.json is for. However, I do not want to name these keys differently in the custom-environment-variables.json file because I want to be able to use 'db' from index.js:
console.log(config.get('db'));
And then based on the results of
config.util.getEnv('NODE_ENV'));
Use the right environment variable (prod_db_key/dev_db_key) under "db".
The things is, I do not want to explicitly ask for prod_db_key or dev_db_key from index.js, that's the whole point. Otherwise, I would have just configured two pairs of key and value in the custom-environment-variables.json file. Does it make sense?
Thanks in advance...