liveconfig

v3.0.0
Read/inject all json/yaml configs under specific directory, and keep runtime updating
live config runtime

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

Metadata

  • MIT
  • Whatever
  • HansHuang
  • released 3/28/2021

Downloads

Maintainers