nconf.file merges don't work correctly #28

andrewrk opened this Issue Jan 25, 2012 · 6 comments

4 participants


2 problems:

  1. nconf.file defaults operate in the wrong order. You can see in this list below that the chain of overriding goes from top to bottom; the things listed higher up override the ones lower down. The nconf.file one operates in the reverse order, however. I had to swap those two lines to get this to work correctly in my app.

  2. If the first file listed is missing, it will delete all config, causing the defaults to be what gets selected. This is bad. Instead it should just not change any config.

  .file({file: "#{process.env.HOME}/.groovebasinrc"})
  .file({file: "/etc/groovebasinrc"})
    log_level: 3
      port: 80
      host: 'localhost'
      port: 6600
      conf: "/etc/mpd.conf"

I remember being burned by this as well. This scenario is not well documented, and perhaps an update should be made since I am not the only one who expected the library to work the way your sample is written.

Anyway, the way things currently stand...

You can only use each of the convenience (argv, env, file, defaults, overrides) methods once because each uses it's name as the key for the config store. If you want to use multiple files, you need to add them like this:

var conf = require('nconf');
conf.add('env-file', {type: 'file', file: path.join(path.resolve(__dirname, '../config'), (conf.get('NODE_ENV') || 'development') + '.json')});
conf.add('default-file', {type: 'file', file: path.resolve(__dirname, '../config/default.json')});

The important part is giving the config store a unique key, which is the first argument passed to add.

I'm surprised this issue sat for a month without a response. What's up, @flatiron ? @indexzero ? @mmalecki ? Is this lib being maintained?


@jstewmon Yes. It is. Unfortunately life can't be all open-source maintenance all the time =D


@jstewmon A pull-request to fix this issue would make you a hero in my book.

@jstewmon jstewmon added a commit to jstewmon/nconf that referenced this issue Mar 2, 2012
@jstewmon jstewmon api and doc change for indexzero/nconf#28 81861d8

@indexzero Watch out - that commit has that showHelp change in it too. Did you ever put that elsewhere? I'd like to align my master with flatiron, but I'm using that feature in a project.

@jfhbrook jfhbrook added a commit that referenced this issue May 4, 2012
@jstewmon jstewmon api and doc change for indexzero/nconf#28 (`.file` may now take a str…
…ing instead of an object)




@pksunkara pksunkara closed this Jun 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment