javascript - How to load config json as environment variable nodejs -


i newbie node js. have different configs different environments viz dev, prod etc. while creating app package copy .json config.json , export config.json config variable (global) , use throughout app.

config = require(__dirname + '/config/config'); (config.httpproxy && config.httpproxy.enabled);

i want load specific env.json part of environment variable (for dev dev.json's keys exported global variable in app) instead of copying app's config.json, same app can used in different env. how that.

ps: application packaging support , dependency management use gulp , npm.

please help.

you can name files this:

config.development.json config.production.json config.test.json 

then load files as:

config = require(__dirname + '/config/config.' + process.env.node_env); 

where process.env.node_env value can development/production/test

you have start application as

node_env=development node app.js 

for work.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -