Skip to content

Read/inject all config json under specific directory, and keep runtime updating

License

Notifications You must be signed in to change notification settings

HansHuang/LiveConfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiveConfig

Read/inject all json or yaml configs under specific directory, and keep runtime updating

NPM version

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

About

Read/inject all config json under specific directory, and keep runtime updating

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published