Giter Club home page Giter Club logo

nconf's Issues

REPL server.start fail

hookio = require('hook.io');
require('repl').start({})
new hookio.Hook

results in the following error:

$ node foo.js 
> 
TypeError: undefined is not a function
    at Object.stores.create (/Users/crabdude/github/node_modules/hook.io/node_modules/nconf/lib/nconf/stores.js:35:10)
    at Provider.use (/Users/crabdude/github/node_modules/hook.io/node_modules/nconf/lib/nconf/provider.js:45:25)
    at Object.<anonymous> (/Users/crabdude/github/node_modules/hook.io/node_modules/nconf/lib/nconf.js:17:7)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/crabdude/github/node_modules/hook.io/node_modules/nconf/lib/nconf/stores/memory.js:8:13)

And it looks like it may be due to this weirdness, though I haven't checked:

nconf.__defineGetter__(name, function () {
    return require('./nconf/stores/' + store)[name];
  });

Bug in optimist 0.3.x version...

Set cli varable like this:

node test.js --myobject.prop=www.google.com

dump optimist.argv show:

{ _: [],
myobject: { prop: -2147483648},
'$0': 'node ./index.js' }

Update to optimist 0.6.x remove this problem

Hierarchical argv overrides clobber entire objects

Here's a simple test case to illustrate what I mean.

test.json:

{
  "database": {
    "host": "localhost",
    "port": 3000
  }
}

test.js:

nconf = require('nconf')

nconf.argv().file({file: 'test.json'})

console.log(nconf.get('database'))

Then run using:

$ node test
{ host: 'localhost', port: 3000 }
$ node test --database:port 8080
{ port: 8080 }

As you can see, the entire database config object is getting clobbered when just one property is overridden. I would have expected just the single property to change/merge.

Is there another way to achieve this?

CLI: why is config changing after app.init()?

I have encountered a strange behaviour of the 'nconf' module, which happens only when used in a flatiron CLI app.

Basically, the config changes for whatever reason, after app.init().

Is this a bug or expected (if so, why?)


just the code, without setup:

// we run this with `node file.js --foo=bar`
console.log('foo: ' + app.config.get('foo'));
// now, `foo` is equal to config from argv

// the `init` changes the `app.config` ???
app.init();

console.log('foo: ' + app.config.get('foo'));
// now, `foo` is equal to config from `file` :/

I made tests with just using nconf, using it with flatiron, and using it as a CLI; it's all in one gist.

Configuration Change Events?

I guess that this is something of a feature request, or maybe just a thought on whether or not such an idea is valid and useful.

I guess what I want is to be notified if some piece of the configuration that I am using has changed for some reason. For example, if I change the value stored in a file, and these values ultimately made there way to being exposed as values in my configuration (that is to say, they have not been overridden by some other values, perhaps given at the command line or something) I would like the rest of my server to be notified so that it can smoothly transition to the new config.

For example, suppose that the port I am listening to for a web service is configured by a value in a config file. I would like to be able to change the config file, and have my service automatically respond to the change.

Perhaps what I a want is an event that I can listen to if some value in the configuration changes, and a new type of store that watches the source data for changes (eg file system watch or a zookeeper node watch).

nconf in shared repository can't find file on server

Hi. I'm using nconf from a shared repository - my app code structure looks like this:

app
  node_modules
    shared
      node_modules
        nconf
      lib
        configuration.js
  config
    production.json
    development.json

When I'm doing this when I set up my config (in shared):

nconf.file(environment, "config/" + environment + ".json");

In development, my code can see my environment-specific config. In production (I'm on nodejitsu), my code can't see productions.json.

I'm using a private git repo for shared, and bundledDependencies in package.json.

How does nconf resolve file paths? I'm assuming cwd() ? If that is the case, any idea why I can't find my production.json but I can find development.json.

Thanks.

Add Store for ENV variables

It would be nice for nconf to be able to interact better with a systems ENV variables.

Adding a store for ENV variables seems like the best choice.

Output final config state

Hello,
how can I output/dump the current state of my config? Assuming I have basic JSON, and then I do nconf.overrides, import .env(), .argv(), etc -- how can I see the final state of affairs (for all the initial variables)? Thanks!

Unexpected nconf.overrides behaviour?

This works as expected, outputting Always be this value whatever the configuration for locals in config.json file:

nconf.overrides({ locals: 'Always be this value' });
nconf.file('./config/config.json');
console.log(nconf.get('locals'));

The following however will allow config.json to have extra keys for locals (foo is preserved, bar is merged):

nconf.overrides({ locals:{ 'foo': 'foo'} });
nconf.file('./config/config.json');
console.log(nconf.get('locals'));

File config.json:

{
    'locals': {
        'bar': 'bar'
    }
}

Is this a wanted behavior?

Memory Store in the chain of stores causes save to fail

I am currently using a memory store definition passed to child objects to keep readonly semantics on a global configuration file. However, calling save at the provider level results in the following exception:

TypeError: Object.keys called on non-object
    at Function.keys (native)
    at C:\util\build\node_modules\nconf\lib\nconf\common.js:96:12
    at Array.forEach (native)
    at Object.merge (C:\util\build\node_modules\nconf\lib\nconf\common.js:95:8)
    at [object Object].save (C:\util\build\node_modules\nconf\lib\nconf\provider.js:425:19)
    at...

Using a configuration hierarchy that looks something like:

    provider = new nconf.Provider({
        stores: [
            { name: 'workspace', type: 'file', file: 'workspace.json' },
            { name: 'buildId',   type: 'file', file: 'buildId.json' },
            { name: 'global',    type: 'memory', loadFrom: ['global.json'] }
        ]
    }); 

Calling save on the provider in turn triggers this logic:

  //
  // If we don't have a callback and the current 
  // store is capable of saving synchronously
  // then do so.
  //
  if (!callback) {
    return common.merge(names.map(saveStoreSync));
  }

The map function triggers saveStoreSync does the following:

    //
    // If the `store` doesn't have a `saveSync` method, 
    // just ignore it and continue. 
    //
    return store.saveSync
      ? store.saveSync()
      : null;

resulting in a null instead of the store object when the method saveSync is undefined on a particular store.

When common.merge is then called:

common.merge = function (objs) {
  var store = new Memory();

  objs.forEach(function (obj) {
    Object.keys(obj).forEach(function (key) {
      store.merge(key, obj[key]);
    });
  });

  return store.store;
};

No check is done on the store prior to using it resulting in the exception listed above.

My workaround for now is to monkey patch the memory store with dummy save/saveSync methods.

win32 support?

Hi, once again ...

it possible to support win32 ??

npm install -g nconf

previous command fails =(

out:

npm ERR! cb() never called!
npm ERR!
npm not ok

Note: im running npm ok ... it works with various others packages ...

thks !

Error on load() when config file doesn't exist

Just getting started with this module, cool stuff. It would be nice if load() would return something in err if the config file wasn't found. I can check for existence before I call load(), but this is redundant. Or if I'm missing something being a noob, please inform. My prototype is trying to load config, if it doesn't exist (initial startup, for example) create a default.

argv-store should convert the strings "true" and "false" to booleans

Example

node app.js --myBool true results in nconf.get('myBool') // 'true'

I think converting boolean-string to real booleans would be nice, because that's what you are expecting - i think the same applies for the env-store.

I will attach a pull request if you agree on my proposal.

Store all

How to save values of all loaded keys?
Or how to get the values ​​of all keys (to save latter)?

  • I need to locally store the values ​​loaded from all sources for next time start

throws "TypeError: Object.keys called on non-object" on json with x:y = null

two files needed to reproduce this bug under nconf 0.6.4 : conf.json and test.coffee

cat conf.json

{
  "x":
  {
    "y":null
  }
}

cat test.coffee

config = require 'nconf'
config.add 'conf_file', type: 'file', file: './conf.json'
xcolony = config.get "x:y"
shell> coffee test
TypeError: Object.keys called on non-object
    at Function.keys (native)
    at common.merge (/home/gord/dev/local/lib/node_modules/nconf/lib/nconf/common.js:96:12)
    at Array.forEach (native)
    at Object.common.merge (/home/gord/dev/local/lib/node_modules/nconf/lib/nconf/common.js:95:8)
    at Provider._execute (/home/gord/dev/local/lib/node_modules/nconf/lib/nconf/provider.js:550:23)
    at Provider.get (/home/gord/dev/local/lib/node_modules/nconf/lib/nconf/provider.js:216:17)
    at Object.<anonymous> (/home/gord/DEV/nconf_check/test.coffee:11:19)
    at Object.<anonymous> (/home/gord/DEV/nconf_check/test.coffee:13:4)
    at Module._compile (module.js:449:26)
    at Object.exports.run (/home/gord/dev/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:79:25)

My reasons for expecting nconf to handle null json keys are :

  • null keys are valid json [ eg. admitted by python -mjson.tool ]
  • null keys are useful in json config files because they keep placeholders, to suggest options for sysadmins/devs
  • I think earlier versions of nconf handled this gracefully

by the way.. we love nconf, it is truly awesome!!

need way to get root of configs

right now conf.get(...) has no way to return the merged roots of all the stores, you can only go one level down and below.

conf.get(null) or conf.get(undefined) should most likely return the root of the config rather than complaining and throwing errors.

Using `defaults`, `env` or `argv` causes save to fail

Having a .defaults call in the chain causes save to fail with an exception as below. The same happens with either .env or .argv present. The examples seem to indicate this should be a valid way to use nconf.

jb@jborg-mbp:~/tmp % npm list
/Users/jb/tmp
└─┬ [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  ├─┬ [email protected] 
  │ └── [email protected] 
  └── [email protected] 

jb@jborg-mbp:~/tmp % cat test.js 
var nconf = require('nconf');
nconf.file({ file: 'settings.json' });
nconf.defaults({
    foo: 'bar'
});
nconf.save();
jb@jborg-mbp:~/tmp % node test.js 

/Users/jb/tmp/node_modules/nconf/lib/nconf/common.js:96
    Object.keys(obj).forEach(function (key) {
           ^
TypeError: Object.keys called on non-object
    at Function.keys (native)
    at /Users/jb/tmp/node_modules/nconf/lib/nconf/common.js:96:12
    at Array.forEach (native)
    at Object.merge (/Users/jb/tmp/node_modules/nconf/lib/nconf/common.js:95:8)
    at [object Object].save (/Users/jb/tmp/node_modules/nconf/lib/nconf/provider.js:425:19)
    at Object.<anonymous> (/Users/jb/tmp/test.js:6:7)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)

nconf multi instance?

Hi,

can i have multiple instances of nconf?

Something like:

var store1 = require('nconf').file({ file: __dirname+'/store1.json'});
var store2 = require('nconf').file({ file: __dirname+'/store2.json'});

store1.set('hello','store1');
store1.save();

store2.set('hello','store2');
store2.save();

This will only save "store2.json" file.

My goal is to read and save in multiple and independent files.
Any suggestion?

Thanks

path.existsSync is now called `fs.existsSync`.

path.existsSync is deprecated since Node 0.7+, please change it to fs.existsSync on line 115 in file lib/nconf/stores/file.js :-)

Edit: Nevermind. For some reason I had nconf version 0.5.0 in use...

Object.keys called on non-object in common.js line 95 when trying to save settings to file

I get this error when I try to save my settings with nconf.

Actual code sample:

nconf.argv()
    .env()
    .file({ file: '../../settings.json' });

nconf.set('database:url', 'tcp://node:[email protected]/node');
nconf.set('server:port', 3000);

nconf.save();

Here’s my stack trace:

{
  "process": {
    "pid": 21552,
    "uid": 502,
    "gid": 502,
    "cwd": "/Users/mikl/Work/Node/knigu",
    "execPath": "/usr/local/Cellar/node/0.6.6/bin/node",
    "version": "v0.6.6",
    "argv": [
      "node",
      "/Users/mikl/Work/Node/knigu/bin/knigu",
      "generate_chapter_pointers"
    ],
    "memoryUsage": {
      "rss": 27222016,
      "heapTotal": 16700608,
      "heapUsed": 9358504
    }
  },
  "os": {
    "loadavg": [
      1.7314453125,
      1.5009765625,
      1.359375
    ],
    "uptime": 113788
  },
  "trace": [
    {
      "column": null,
      "file": null,
      "function": "Function.keys",
      "line": null,
      "method": "keys",
      "native": true
    },
    {
      "column": 12,
      "file": "/Users/mikl/Work/Node/knigu/node_modules/nconf/lib/nconf/common.js",
      "function": null,
      "line": 97,
      "method": null,
      "native": false
    },
    {
      "column": null,
      "file": null,
      "function": "Array.forEach",
      "line": null,
      "method": "forEach",
      "native": true
    },
    {
      "column": 8,
      "file": "/Users/mikl/Work/Node/knigu/node_modules/nconf/lib/nconf/common.js",
      "function": "Object.merge",
      "line": 95,
      "method": "merge",
      "native": false
    },
    {
      "column": 19,
      "file": "Object].save (/Users/mikl/Work/Node/knigu/node_modules/nconf/lib/nconf/provider.js",
      "function": "[object",
      "line": 415,
      "method": null,
      "native": false
    },
    {
      "column": 9,
      "file": "/Users/mikl/Work/Node/knigu/lib/commands/generate_chapter_pointers.js",
      "function": null,
      "line": 18,
      "method": null,
      "native": false
    },
    {
      "column": 19,
      "file": "/Users/mikl/Work/Node/knigu/node_modules/flatiron/lib/flatiron/plugins/cli.js",
      "function": "executeCommand",
      "line": 179,
      "method": null,
      "native": false
    },
    {
      "column": 5,
      "file": "/Users/mikl/Work/Node/knigu/node_modules/flatiron/lib/flatiron/plugins/cli.js",
      "function": "",
      "line": 224,
      "method": null,
      "native": false
    },
    {
      "column": 21,
      "file": "Object].dispatch (/Users/mikl/Work/Node/knigu/node_modules/flatiron/node_modules/director/lib/director/cli.js",
      "function": "[object",
      "line": 50,
      "method": null,
      "native": false
    },
    {
      "column": 18,
      "file": "/Users/mikl/Work/Node/knigu/node_modules/flatiron/lib/flatiron/plugins/cli.js",
      "function": null,
      "line": 58,
      "method": null,
      "native": false
    }
  ],
  "stack": [
    "TypeError: Object.keys called on non-object",
    "    at Function.keys (native)",
    "    at /Users/mikl/Work/Node/knigu/node_modules/nconf/lib/nconf/common.js:97:12",
    "    at Array.forEach (native)",
    "    at Object.merge (/Users/mikl/Work/Node/knigu/node_modules/nconf/lib/nconf/common.js:95:8)",
    "    at [object Object].save (/Users/mikl/Work/Node/knigu/node_modules/nconf/lib/nconf/provider.js:415:19)",
    "    at /Users/mikl/Work/Node/knigu/lib/commands/generate_chapter_pointers.js:18:9",
    "    at executeCommand (/Users/mikl/Work/Node/knigu/node_modules/flatiron/lib/flatiron/plugins/cli.js:179:19)",
    "    at Object.<anonymous> (/Users/mikl/Work/Node/knigu/node_modules/flatiron/lib/flatiron/plugins/cli.js:224:5)",
    "    at [object Object].dispatch (/Users/mikl/Work/Node/knigu/node_modules/flatiron/node_modules/director/lib/director/cli.js:50:21)",
    "    at /Users/mikl/Work/Node/knigu/node_modules/flatiron/lib/flatiron/plugins/cli.js:58:18"
  ],
  "level": "error",
  "message": "uncaughtException"
}

nconf.file - how to specify namespace

Hi - it's not clear to me from the docs how to add a custom namespace when loading a file, I would expect:

// Or with a custom name
//
nconf.file('custom', '/path/to/config.json');

Assuming config.json to be something like:
{ key: 'foo', secret: 'bar' }

To be accessed like:
nconf.get('custom:key')
nconf.get('custom:secret')

But both those return undefined, instead you access them like:
nconf.get('key');
nconf.get('secret');

I want to namespace my configs so I can load multiple configs into the same nconf object. I don't want to have to namespace in my config json e.g.
{ s3-ket: 'foo', s3-secret: 'bar' }

So how to set a namespace when loading from a file?

Thanks

nconf store memory has no loadSync() method

When I try this:

var nconf = require('nconf');

nconf.use('memory');
nconf.load();

I get this error

Error: nconf store memory has no loadSync() method
at loadStoreSync (./lib/nconf/provider.js:300:13)
at Array.map (native)
at loadBatch (./lib/nconf/provider.js:318:35)
at [object Object].load (./lib/nconf/provider.js:362:7)
at repl:1:7
at REPLServer.eval (repl.js:80:21)
at repl.js:190:20
at REPLServer.eval (repl.js:87:5)
at Interface. (repl.js:182:12)
at Interface.emit (events.js:67:17)

nconf.overrides won't merge as expected

Calling nconf.overrides the second time will replace every options set the first time.

nconf.overrides({
  modules1: {prop1: 'abc', prop2: 'def'}
});

// The following will replace every object in nconf.overrides specified before
nconf.overrides({
  moduleA: {newProp: 'foo'}
});

Am I doing it right? Is it the intended behavior of nconf.overrides?

using several stores / overrides - merges not as expected

Hi,
I'm trying to set up store as such:

conf.add 'user',   { type: 'file', file: 'config/config.local.json' }
conf.add 'global', { type: 'file', file: 'config/config.json' }

I then expect the user values to override the global values such that:

# user
{ port:4000}

# global
{ port:80}

but in every case i'm getting port:80 being resloved.
if i reverse the order like so:

conf.add 'global', { type: 'file', file: 'config/config.json' }
conf.add 'user',   { type: 'file', file: 'config/config.local.json' }

then i get undefined values, because global declares more values than in user.

# global
{ port:80, db:"host"}

# user
{ port:4000}

db is undefined -- seems to be overriden in user - but i'm not specifying it there in any case and expecting it to be merged from global.

anything i'm doing wrong here?

Thanks!

save error, but saves ...

Hi,

Im using nconf for a while ... and today making some refactors in my jakefile i found error when nconf save data (file mode), take a look :

var 
  nconf = require('nconf').use('file', { file: 'build.json' });
  version = nconf.get('version'),
  debug = nconf.get('debug'),
  development = nconf.get('development');
//...
nconf.set('build', new Date().getTime());  
//...
nconf.save(function (err) {
  if (err) {
    console.error(err.message); // nconf store system has no save() method ?!?!?
    return;
  }
});

the save method throws an exception "nconf store system has no save() method" but updates the use file ...

im doing someting wrong or its an issue ?? why exception says ... "store system" ... ??

thks guys !

api to call optimist.usage()

I would love to invoke usage() if the user specifies --help, for example. Is there any way to do that now? If not, can it be added please?

Allow for multiple defaults

It would be really slick if we could something like the following:

nconf
.file('config', '/path/to/config')
.defaults({store: {user: {firstName: 'John', lastName: 'Doe'}}})
.defaults({store: {path: nconf.get('user:firstName') + ' ' nconf.get('user:lastName')}});

Otherwise, it gets messy when you have default values that depend on other default values.

Regression: Uncaught exception when getting nested keys

When you set something to a string value and then attempt to get a child of that string value an unhandled Error is thrown.

This is a direct caused by incorrect use of the in keyword in #49

e.g.

  var nconf = require('nconf');
  nconf.set('foo:bar', 'SOME_STRING_VAUE');

  console.log(
    nconf.get('foo:bar:doesnt:exist') // should be undefined but throws
  );

Wrong error description when parse error.

nconf.file({file: '/path/to/a/bad/format/ini/file', format: nconf.formats.ini})

parse bad ini file throws "Error parsing your JSON configuration file"

It made me confuse to debug.

Maybe "Error parsing /path/to/a/bad/format/ini/file configuration file" is better?

Asynchronous not getting executed after checking synchronous

I am using file store to save some config and I called save() without any callback given. nconf then checked for any synchronous execution and threw error when not found.

I think, it should continue to check async execution and then use it with a dummy callback.

Provide the way to override attributes of settings

I'm trying to provide several configuration files which are overriding each other

config-default.json's settings are overriden by config-{DEV_ENV}.json and these by config-local.json

I'm using this:

conf.add('local-file', {'type': 'file', file: path.join(__dirname, './config-local.json')});
var current_env = process.env['DEV_ENV'] || 'development';
conf.add('env-file', {'type': 'file', file: path.join(__dirname, './config-' + current_env + '.json')});
conf.add('default-file', {'type': 'file', file: path.join(__dirname, './config-default.json')});

It's working well, however I'm unable to override parts of the object:
if config-default.json has a setting settingA defined in such way:

{
    "settingA": {
        "attributeA": "valueA",
        "attributeB": "valueB"
    }
}

it can be accessed by conf.get('settingA:attributeA'). I wish to override just this value in any other file. This is not working for obvious reasons (overrides entire setting):

{
    "settingA": {
        "attributeA": "localValueA"
    } 
}

But there is a syntax which isn't used and could work well:

{
    "settingA:attributeA": "localValueA"
}

Please tell me it's sane and if I'm using your lib in the right way.

Live reload for power users

Hey...

I've found a lot of cases when i'd like to be able to set up a live reload of config options, without restarting the instance, e.g.
nconf.onChange ->
do stuff

or even fancier:
nconf.onChange (changeset?)->
do stuff

this might be a handy feature as part of the core functionality...

Incorrect module name in the redis.js file.

Hi,

Please correct module name in the lib/nconf/stores/redis.js line 5:

Memory = require('./Memory').Memory;

It must be:

Memory = require('./memory').Memory;

At the moment there is the following error:

$ node
> var nconf = require('nconf');
Error: Cannot find module './Memory'
    at Function._resolveFilename (module.js:320:11)
    at Function._load (module.js:266:25)
    at require (module.js:348:19)
    at Object. (/usr/local/lib/node/.npm/nconf/0.1.1/package/lib/nconf/stores/redis.js:11:14)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at require (module.js:348:19)
    at Object. (/usr/local/lib/node/.npm/nconf/0.1.1/package/lib/nconf/stores.js:16:17)
>

Thanks,
Alexey Ozerov.

nconf.file merges don't work correctly

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.
nconf
  .argv()
  .env()
  .file({file: "#{process.env.HOME}/.groovebasinrc"})
  .file({file: "/etc/groovebasinrc"})
  .defaults
    log_level: 3
    http:
      port: 80
    mpd:
      host: 'localhost'
      port: 6600
      conf: "/etc/mpd.conf"

ERR wrong number of arguments for 'set' command

Could you please have a look what's wrong with redis storage engine?
Just run the script below to reproduce the issue.

Test script:

var nconf = require('nconf');
nconf.use('redis');
nconf.set('database:host', '127.0.0.1');
nconf.set('database:port', 5984);

Error log:

node_redis: no callback to send error: Error: ERR wrong number of arguments for 'set' command
node_redis: no callback to send error: Error: ERR wrong number of arguments for 'set' command

node.js:116
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Error: ERR wrong number of arguments for 'set' command
    at HiredisReplyParser. (/usr/local/lib/node/.npm/redis/0.5.9/package/index.js:84:27)
    at HiredisReplyParser.emit (events.js:42:17)
    at HiredisReplyParser.execute (/usr/local/lib/node/.npm/redis/0.5.9/package/lib/parser/hiredis.js:33:22)
    at RedisClient.on_data (/usr/local/lib/node/.npm/redis/0.5.9/package/index.js:328:27)
    at Socket. (/usr/local/lib/node/.npm/redis/0.5.9/package/index.js:99:14)
    at Socket.emit (events.js:42:17)
    at Socket._onReadable (net.js:649:14)
    at IOWatcher.onReadable [as callback] (net.js:156:10)

Additional info: after this error redis contains the following data:

$ redis-cli 
redis> keys *
1) "nconf:database:keys"
2) "nconf:keys"

Strict Mode

Please upgrade your version of async; running an app using nconf in strict mode results in the following error:

../node_modules/nconf/node_modules/async/lib/async.js:8
previous_async = root.async;
^
TypeError: Cannot read property 'async' of undefined

File override is not working

AppConfigDefaults.json:

{
    "dev": {
        "appRoot": "defaultAppRootDev"
    },
    "dist": {
        "appRoot": "defaultAppRootDist"
    }
}

AppConfigOverrides.json:

{
    "dev": {
        "appRoot": "overrideAppRootDev"
    }
}

Code:

nconf
    .file({file: 'AppConfigOverrides.json'})
    .file({file: 'AppConfigDefaults.json'});
console.log("dev.approot=" + nconf.get('dev').appRoot);
console.log("dist.approot=" + nconf.get('dist').appRoot);

prints:

dev.approot=defaultAppRootDev
dist.approot=defaultAppRootDist

Defaults file is not overridden by Overrides file for dev.approot.

Am I doing something wrong?

nconf.defaults: "Object has no method 'defaults" (Example from readme.)

This example from the readme, doesn't seem to work, gives the following errors:

TypeError: Property 'overrides' of object [object Object] is not a function
TypeError: Property 'env' of object [object Object] is not a function
TypeError: Object [object Object] has no method 'file'
TypeError: Object [object Object] has no method 'defaults'

Am I missing something?

var nconf=require('nconf');

  //
  // 1. any overrides
  //
  nconf.overrides({
    'always':'be this value'
  });

  //
  // 2. `process.env`
  // 3. `process.argv`
  //
  nconf.env().argv();

  //
  // 4. Values in `config.json` 
  //
  nconf.file({file:'config.json'});

  //
  // 5. Any default values
  //
  nconf.defaults({
    'if nothing else':'use this value'
  });

defaults behave like overrides if specified before other stores

Defaults behave like overrides if specified before other stores.

var nconf = require('nconf');

nconf.defaults({
  'ATTACK_ROLE': 'ninjas'
});

process.env['ATTACK_ROLE'] = 'pirates';
var whitelist = ['ATTACK_ROLE'];

nconf.env({
  whitelist: whitelist
});

console.log(nconf.get('ATTACK_ROLE')); //ninjas

In this case, even though I have an environment variable with the value 'pirates', I will always get 'ninjas'. If the call to defaults() is placed after env(), I will get 'pirates'.

I expect a default to be provided IF no other store has a value for a specified key, regardless of the order in which I declare stores.

Descriptions provided to optimist.usage(...) are suppressed

nconf does not implement .usage(...) method.
I tried the following, but could not get nconf to display the usage message, or understand what I need to do to make it work.

The test code: test.js

var nconf = require('nconf');

require('optimist')
   .usage("This is explanation of usage");

nconf.argv(
  { x: 
    { demand: true
    , describe: "this is an x"
    , aliax : "xxs"
    }
  , y: 
    { demand: true
    , describe: "this is a y"
    , aliax : "yxs"
    }
  }
)

console.log( "x : %s, y: %s", nconf.get("x") , nconf.get("y") );

run as : node test.js

Expected:

This is explanation of usage

Options:
  -x, --xxs  this is an x  [required]
  -y, --yxs  this is a y   [required]

Missing required arguments: x, y

Found:

Options:
  -x  this is an x  [required]
  -y  this is a y   [required]

Missing required arguments: x, y

Mind also that the aliases are not displayed on the description

wish: option to lock() the configuration, so set() commands no longer work.

set() could be useful during a configuration phase, but once the app has started, for some use cases it would be a feature if the configuration could be "locked"-- that is: read-only, immutable.

Having a 'set' method available and usable gives the impression that it could be a good idea to change a configuration value deep within the application. This could cause an 'action at a distance' bug if code elsewhere in the application continues to expect that the value from the configuration file value is a constant.

Explicitly disabling the set() method would provide an immediate to a developer that using set() after configuration is done is not the way to do things.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.