-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwatcher.js
More file actions
32 lines (27 loc) · 739 Bytes
/
watcher.js
File metadata and controls
32 lines (27 loc) · 739 Bytes
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
const main = 'app.js';
var process = require('process');
var cp = require('child_process');
var fs = require('fs');
var server = cp.fork(main);
console.log('Server started');
fs.watch('.', { recursive: true }, function (event, filename) {
console.log(`${filename} file changed on disk...`);
if (filename.match(/\/ui\//)) {
console.log('ui code... ignoring');
return;
}
if (!filename.match(/\.js$/)) {
console.log('not a javascript file... ignoring');
return;
}
console.log(`reloading ${main}`);
server.kill();
console.log('Server stopped');
server = cp.fork(main);
console.log('Server started');
});
process.on('SIGINT', function () {
server.kill();
fs.unwatchFile(main);
process.exit();
});