Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobbubu/nconf-watchfile
Add a prototype method `watchFile` to `nconf.Prodiver` for auto-reloading any change in your config file.
https://github.com/jacobbubu/nconf-watchfile
Last synced: 14 days ago
JSON representation
Add a prototype method `watchFile` to `nconf.Prodiver` for auto-reloading any change in your config file.
- Host: GitHub
- URL: https://github.com/jacobbubu/nconf-watchfile
- Owner: jacobbubu
- Created: 2017-04-16T15:04:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-16T15:45:56.000Z (almost 8 years ago)
- Last Synced: 2024-12-13T19:45:55.275Z (about 1 month ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nconf-wacthfile
Add a prototype method `watchFile` to `nconf.Prodiver` for auto-reloading any change in your config file.
## Usage
``` bash
npm i nconf-wacthfile
```In your node file:
``` js
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
1. **file**: refer to https://github.com/indexzero/nconf#file. You can use any options that `nconf.file` accepted(`secure`, `format`).
2. **onChange(store, path)**: A callback will be fired while config file changed. `store` is the parsed value.
3. **onError(err, path)**: A callback will be fired while parsing failed.
4. **watch**: Chokidar [optinons](https://github.com/paulmillr/chokidar#api) for file change monitoring.
* I've set `watch.ignoreInitial = true` to ignore first change event.## Test
TBD.#### Author: Rong Shen
#### License: MIT