https://github.com/soarez/liveconf
An npm module to allow live updates on JSON configuration files
https://github.com/soarez/liveconf
Last synced: about 1 month ago
JSON representation
An npm module to allow live updates on JSON configuration files
- Host: GitHub
- URL: https://github.com/soarez/liveconf
- Owner: soarez
- License: mit
- Created: 2012-08-04T18:12:00.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-10-08T14:47:49.000Z (over 13 years ago)
- Last Synced: 2025-02-18T03:14:55.353Z (over 1 year ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## liveconf
A very simple and barebones configuration module. Just allows runtime configuration objects to be synced with JSON configuration files.
**For a much more solid module on cofiguration, check out [node-config](https://github.com/lorenwest/node-config). **
### Install
npm install liveconf
### Use
Have a configuration file with some configuration. e.g. `config.json`
```json
{
"a":8,
"b":"foo"
}
```
```javascript
var liveconf = require('liveconf');
// get the configuration from a file
var config = liveconf('config.json');
console.log(config.b); // foo
```
The configuration object will be cached and will always be the same for the same configuration file. The configuration file is watched so any changes are reflected on the object.
While the code is running you can change the configuration.
```json
{
"b":"bar",
"c":42
}
```
```javascript
console.log(config.b); // bar
```
#### Events
Each configuration object exposes an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) through a non-enumerable readonly property `ee`. There is only one event `changed`, fired when the configuration object is changed.
```javascript
var liveconf = require('liveconf');
var config = liveconf('config.json');
config.ee.on('changed', function() {
// config file has changed
});
```
### License
MIT