forked from statsd/statsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
42 lines (31 loc) · 995 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*jshint node:true, laxcomma:true */
const fs = require('fs')
const util = require('util');
let Configurator = function (file) {
let self = this;
let config = {};
let oldConfig = {};
this.updateConfig = function () {
util.log('[' + process.pid + '] reading config file: ' + file);
fs.readFile(file, function (err, data) {
if (err) { throw err; }
old_config = self.config;
self.config = eval('config = ' + data);
self.emit('configChanged', self.config);
});
};
this.updateConfig();
fs.watch(file, function (event, filename) {
if (event == 'change' && self.config.automaticConfigReload != false) {
self.updateConfig();
}
});
};
util.inherits(Configurator, require('events').EventEmitter);
exports.Configurator = Configurator;
exports.configFile = function(file, callbackFunc) {
let config = new Configurator(file);
config.on('configChanged', function() {
callbackFunc(config.config, config.oldConfig);
});
};