-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
59 lines (52 loc) · 1.35 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const Config = require("config-watch");
const configObj = {
config: undefined,
initialized: false,
init(cb) {
if (this.initialized) {return};
this.initialized = true;
console.log('Config init...')
this.config = new Config("config.json", {
defaults: {
sheduler: [
{
start: "17:00",
stop: "24:00"
},
{
start: "00:00",
stop: "07:45"
},
],
mqtt_ip: '192.168.179.27',
debug: false,
test_date: '',
test_all_on: false,
days_less_24 : 'ON',
}
},(err, config) => {
if (err) {
console.error('There was an error reading the config file!', err);
return;
}
console.log("Config loadet:\n"+this, config.get());
});
this.config.on("change", (err, config) => {
if (err) {
console.error('There was an error reading the config file!', err);
return;
}
console.log("Config changed. The new config is:\n", config.get());
});
},
get(key) {
try {
return this.config.get(key);
} catch (err) {
// This will not catch the throw!
console.error('Config noch nicht geladen!');
};
},
};
module.exports = configObj;