1.0.6 • Published 7 years ago

nodejs-live-config v1.0.6

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

NodeJS Live Config

A module to watch for the config files changes made outside the app and apply the changes without the application restart.

Getting Started

Put a config or configs to a som directory and start watch for them. Since then the each invocation of the LiveConfig() will return the most fresh state of a config/configs

Use:

const LiveConfig = require ('live-config');
...
config.watch('./etc','config1.json');
...
console.log(LiveConfig().prop1)
...
config.unwatch();

Sampe JSON configs:

etc/config1.json

{
  "prop11":11,
  "prop12":12
}

etc/config2.json

{
  "prop21":21,
  "prop22":2w
}

One config file

const LiveConfig = require ('live-config');
...
config.watch('../etc','config1.json');
...
console.log(LiveConfig());
/* outputs
{
  "prop11":11,
  "prop12":12
}

 */
...
config.unwatch();

Few configs

const LiveConfig = require ('live-config');
...
config.watch('../etc',['config1.json','config2.json']);
...
console.log(LiveConfig());
/* outputs
{
 "config1":
	{
		"prop11":11,
		"prop12":12
	},
 "config2":
	{
		"prop21":21,
		"prop22":22
	}

 */
...
config.unwatch();

Listen for changes:

const config=Config.watch('../etc',['configA.json','configB.json']);
config.events.on('change',function (config,name){...})

The configs are "required" so they may be any valid JS/JSON script.

Installing

npm install nodejs-live-config
1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago