-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonfile.js
40 lines (31 loc) · 1.04 KB
/
jsonfile.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
var fs = require('fs');
var configPath = __dirname + '/config.json';
var defaultConfig = {
installed: false
}
// if the config.json file exists, read it. Otherwise make the
// config.json file with defaultConfig as the file's contents
var read = function(){
if (!fs.existsSync(configPath)){
module.exports.save(defaultConfig);
return defaultConfig;
} else {
return JSON.parse(fs.readFileSync(configPath));
}
};
module.exports = {
// update the config file
save: function(){
fs.writeFileSync(configPath, JSON.stringify(this.config, null, ' '));
module.exports.config = this.config;
},
// make the config variable accessable by reading the
// config file and setting module.exports.config which
// will be a variable containing the contents of the config
init: function(){
module.exports.config = read();
if (!this.config.installed){
console.log('This is probably the first time running. Please make an admin account by going to http://localhost:' + (process.env.PORT || 3000) + '\n');
}
}
}