0

I am loading config.json file using nconf like below:

nconf.file({ file: '../config.json' });

. I am using a property in that config file which I can print on console and it works:

console.log('mailhost: '+ nconf.get('mailhost'));

But my requirement is to have an object where I can dynamically put nconf properties like so:

var mailConfig = {
    "mailhost": nconf.get('mailhost')
};
console.log('mailConfig: '+ JSON.stringify(mailConfig));

The above doesn't work as it prints empty object on console.

However, if I happen to load the config.json file using node like so:

var config = require('../config.json');

And use it to do exact same I did with nconf then it works well:

    var mailConfig = {
    "mailhost": config.mailhost
};
console.log('mailConfig: '+ JSON.stringify(mailConfig));

What am I missing?

sunny_dev
  • 765
  • 3
  • 15
  • 34
  • You appear to have a typo with capitalization in the argument to `.get()` -- `mailHost` in the 1st (upper `H`) vs. `mailhost` in the 2nd (lower `h`). – Jonathan Lonowski Oct 17 '15 at 21:06
  • Side note: `console.log()` will format an object, listing its keys and values, if it's provided as a separate argument -- `console.log('mainConfig:', mailConfig);`. Using this would have likely shown you `mainConfig: { mailhost: undefined }`. – Jonathan Lonowski Oct 17 '15 at 21:10
  • my mistake while typing in stackoverflow. I corrected it. This typo issue is not there in actual code. – sunny_dev Oct 17 '15 at 22:46

0 Answers0