简体   繁体   中英

NodeJS config.json vs process.env for configuartion management

I've come across people using both methods to do config management.

What are the pros and cons of each approach?

If I have a lot of variables that I store in my config object, will I have to set them all one by one in an upstart script before executing the node app?

You generally use envvar to keep an application stateless. The same codebase should work in dev, staging, test and production environment. You will put var like MySQL config, API keys, if log is enabled or not, if debug is on or not ...

Config file are used for variables which are not dependent of the environment. For instance, name of the application, number of items per page ...

I guess you can use config.json file for storing big configs. ENV I've usually use for passing application port or something very important for normal application start. For example if you use some external lib, it's better to be able to pass custom path to lib executor in ENV. PS You should never save config.json in SVN.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM