nconf icon indicating copy to clipboard operation
nconf copied to clipboard

Documentation does not make it clear how to specify keys for Literal storage

Open qbolec opened this issue 10 years ago • 1 comments

Afer reading https://www.npmjs.com/package/nconf I was surprised that

nconf.argv().env().defaults({
  'port':8815,
  'faye:endpoint': "http://localhost:8813/pubsub",
})

does not work. I finally guessed that the correct way to do that is:

nconf.argv().env().defaults({
  'port':8815,
  'faye':{
    'endpoint': "http://localhost:8813/pubsub",
  }
})

but this is not clear from examples given on the mentioned site, nor from wording.

More importantly it's not clear to me what is the semantic, of the later form - how are two or more such literals merged together? For example if I have

  'faye':{
    'password': "lolcat",
  }

somewhere in the hierarchy with a higher priority (say in overrides()), then, what will be the result of get('faye:endpoint') - will it be undefined, or "http://localhost:8813/pubsub"? My experiments show that the objects will be merged. The question is important for cases where merging values from different places together does not result in a semantically good value (a particular example I have in my mind is defining a list of servers for db sharding, where merging 2 production servers with 1 development server is not what you want). This is why I expected that the syntax for Literal storage is to use 'faye:endpoint' as the key - this way it would be explicit what is my intention: if I wanted to propose a default for the whole faye branch of the config tree I would write:

{
  'faye':{
    'endpoint':  "http://localhost:8813/pubsub",
  }
}

and if I only wanted to add a possibly missing child faye:endpoint I'd write:

{
  'faye:endpoint':"http://localhost:8813/pubsub",
}

qbolec avatar Dec 16 '15 15:12 qbolec

Was trapped in the same problem, thanks for the detailed description. I agree it should be as you described. For now I can at least continue with my coding.

tekgator avatar Jan 03 '21 22:01 tekgator