简体   繁体   中英

Node-config: How to pick environment specific config file

In our Node.JS application, we have been specifying application environments (dev, qa, stage, prod, etc.) in package.json as below:

"start-prod": "NODE_ENV=prod node./bin/www",

"start-qa": "NODE_ENV=qa node./bin/www"

etc.

However, we have realized recently that using NODE_ENV in this manner to specify app environments is not a good practice. So, I am trying to use the npm package node-config for this purpose as well as for loading environment-specific configuration which is currently coming from AWS Parameter Store since there seem multiple advantages of using overriding config files over repeated configuration in AWS Parameter Store.

Therefore, I have created different config.json files, eg, dev.config.json, qa.config.json, etc. But I am not sure how to specify/read the environment (qa, dev, stage, prod, etc.) and load configuration from the corresponding config.json file.

It may be a very stupid question but I am not able to find a good implementation example for node-config. Any help will be highly appreciated.

As documented on the node-config wiki , you can create:

default.js
prod.js
dev.js
qa.js

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