Is there any method in nconf
to collect all the keys from all the stores into a single object?
Imagine I've got this little script:
assert = require('assert');
nconf = require('nconf');
nconf.argv().env().defaults({'C': 3});
assert.equal(nconf.get('A'), 1);
assert.equal(nconf.get('B'), 2);
assert.equal(nconf.get('C'), 3);
assert.deepEqual({'A':1, 'B':2, 'C':3}, nconf.X); // <-- What's X?
that I run with
A=1 node script.js -B 2
Is there an nconf.X
that will pass the test? I'd even settle for listing all the configured keys.
Yes to get the object you can do the following;
nconf.get();
it will fail the test as argv will with the exec string and env will have a lot more variables though.
You could whitelist the env call using the following
nconf.env({whitelist: 'A'});
Also the defaults adds a 'type' with value 'literal' to the resulting output.
For a test that passes you could use this;
var assert = require('assert'),
nconf = require('nconf');
nconf.argv().env({whitelist: ['A']}).defaults({'C': 3});
assert.equal(nconf.get('A'), 1);
assert.equal(nconf.get('B'), 2);
assert.equal(nconf.get('C'), 3);
var object = nconf.get();
delete object.type;
delete object['$0'];
delete object['_'];
assert.deepEqual({'A':1, 'B':2, 'C':3}, object);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With