liveconfig
v3.0.3
Published
Read/inject all json/yaml configs under specific directory, and keep runtime updating
Downloads
8
Readme
LiveConfig
Read/inject all json or yaml configs under specific directory, and keep runtime updating
Install
$ npm install liveconfig -S
Usage
/*
* there are 2 files in configDir:
* user.json: {name: 'hans'}
* system.yaml: domain: 'b.cc'
*/
let config = liveconfig(configDir)
console.log(config.user.name) //'hans'
console.log(config.system.domain) //'b.cc'
// update system.yaml file with new content: domain: a.cc
console.log(config.system.domain) //'a.cc'
// if you want to catch the event, pass me the event emittor
let eventEmitter = new require('events').EventEmitter(),
config = liveconfig(myDir, eventEmitter)
eventEmitter.on('config.error', filename => {
console.log(`failed to read config: ${filename}`)
})
// if you want to stop config file watching, emit a "stop" event
// eventEmitter.emit('config.stop')