Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using multiple files how to save to specific one? #406

Open
WeaponX86 opened this issue Apr 28, 2022 · 3 comments
Open

When using multiple files how to save to specific one? #406

WeaponX86 opened this issue Apr 28, 2022 · 3 comments

Comments

@WeaponX86
Copy link

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?
@LongLiveCHIEF
Copy link

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'))

@mhamann
Copy link
Collaborator

mhamann commented Sep 9, 2022

I haven't tested the above, but that looks correct to me. PRs are always welcome :-)

@LongLiveCHIEF
Copy link

Unfortunately, it did not work. At this point, i'm just using my own save function for writing to disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants