forked from HYPER-MOD/Queen-Alexa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
78 lines (62 loc) · 1.74 KB
/
run.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const express = require('express');
const fs = require("fs");
var process = require('process');
var cp = require('child_process');
require("./main.js");
nocache("./main.js", (module) => console.log(`${module} is now updated!`));
require("./Queen-Alexa.js");
nocache("./Queen-Alexa.js", (module) => console.log(`${module} is now updated!`))
;
var server = cp.fork('main.js');
console.log('Server started');
fs.watchFile('main.js', function (event, filename) {
server.kill();
console.log('Server stopped');
server = cp.fork('main.js');
});
fs.watchFile('Queen-Alexa.js', function (event, filename) {
server.kill();
console.log('Server stopped');
server = cp.fork('main.js');
});
process.on('SIGINT', function () {
server.kill();
fs.unwatchFile('main.js');
console.log('Server started');
process.exit();
});
process.on('SIGINT', function () {
server.kill();
fs.unwatchFile('Queen-Alexa.js');
console.log('Server started');
process.exit();
});
/**
* Uncache if there is file change
* @param {string} module Module name or path
* @param {function} cb <optional>
*/
function nocache(module, cb = () => {}) {
console.log("Module", `'${module}'`, "is now being watched for changes");
fs.watchFile(require.resolve(module), async () => {
await uncache(require.resolve(module));
cb(module);
});
}
/**
* Uncache a module
* @param {string} module Module name or path
*/
function uncache(module = ".") {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(module)];
resolve();
} catch (e) {
reject(e);
}
});
}
const app = express();
const port = 3000;
//app.listen(port, () => console.log(`server running on http://localhost:${port}`));