简体   繁体   中英

How to define default value for nconf globaly?

I'm trying to put my development project live. So to handle config I'll use nconf .

I have defined on heroku my config var :

NODE_ENV: production

And I have a config object on dev:

config = {
  NODE_ENV: development
}

On the app.js file, I require nconf and I configure the priority order to args, env vars, and finally default config object (and it's work):

var nconf = require('nconf');
nconf.argv()
 .env()
 .defaults(config);
console.log(nconf.get('NODE_ENV')); // development || production

But now I try to use nconf on other file, or lib (required after the previous lines) and it didn't work. I have to copy/past the priority order on each file to configure my default config.

Do I have a solution to define this only one time, and re-use it on each file/lib/controller...

Thank

The process object is a global object and can be accessed from anywhere.

Refer https://nodejs.org/api/process.html#process_process

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