When using multiple files how to save to specific one?
In the example you can open multiple files. When you run save(), how do I specify where it goes?
nconf.file('path/to/your/config.json');
// add multiple files, hierarchically. notice the unique key for each file
nconf.file('user', 'path/to/your/user.json');
nconf.file('global', 'path/to/your/global.json');
nconf.set('foo','bar');
nconf.save(); // Where is 'foo' saved?
So I've been looking into this as well. At the moment, with your example, foo would be saved to the 'global' file.
I've been looking at the tests, (specifically for the file store) and I think I've figured out how to control where things are saved. I'm testing this out right now, and will probably submit a PR for documentation when this is done, but the gist of this is that instead of using nconf.file() for both of your files, you can do this:
nconf.file('path/to/your/config.json')
const userStore = new nconf.File('path/to/your/user.json')
userStore.load() // I think this loads/merges onto the memory store
const globalStore = new nconf.File('path/to/your/global.json')
globalStore.load() // i think this loads/merges onto the memory store
nconf.set('foo', 'bar')
// now we save to the path/to/your/user.json
userStore.save((err) => console.error('problem saving to path/to/your/user.json'))
I haven't tested the above, but that looks correct to me. PRs are always welcome :-)
Unfortunately, it did not work. At this point, i'm just using my own save function for writing to disk.