nconf-watchfile
v0.1.3
Published
Add a prototype method `watchFile` to `nconf.Prodiver` for auto-reloading any change in your config file.
Downloads
12
Readme
nconf-wacthfile
Add a prototype method watchFile
to nconf.Prodiver
for auto-reloading any change in your config file.
Usage
npm i nconf-wacthfile
In your node file:
var nconf = require('./lib/nconf-watchfile');
nconf.env({
whitelist: ['host']
}).watchFile({
file: './test/test-config.json',
onChange: function(/* store, path*/) {
console.log(nconf.get());
},
onError: function(err, path) {
console.error(err, path);
}
}).defaults({
host: 'DEFAULT_HOST'
})
console.log(nconf.get())
Any change in './test/test-config.json' in occured after watchFile
calling will be merged to nconf store.
Options
- file: refer to https://github.com/indexzero/nconf#file. You can use any options that
nconf.file
accepted(secure
,format
). - onChange(store, path): A callback will be fired while config file changed.
store
is the parsed value. - onError(err, path): A callback will be fired while parsing failed.
- watch: Chokidar optinons for file change monitoring.
* I've set
watch.ignoreInitial = true
to ignore first change event.
Test
TBD.