forked from statsd/statsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
39 lines (28 loc) · 880 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
var fs = require('fs')
, sys = require('sys')
var Configurator = function (file) {
var self = this;
var config = {};
var oldConfig = {};
this.updateConfig = function () {
sys.log('reading config file: ' + file);
fs.readFile(file, function (err, data) {
if (err) { throw err; }
old_config = self.config;
self.config = process.compile('config = ' + data, file);
self.emit('configChanged', self.config);
});
};
this.updateConfig();
fs.watchFile(file, function (curr, prev) {
if (curr.ino != prev.ino) { self.updateConfig(); }
});
};
sys.inherits(Configurator, process.EventEmitter);
exports.Configurator = Configurator;
exports.configFile = function(file, callbackFunc) {
var config = new Configurator(file);
config.on('configChanged', function() {
callbackFunc(config.config, config.oldConfig);
});
};