-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
28 lines (23 loc) · 737 Bytes
/
Copy pathdev-server.js
File metadata and controls
28 lines (23 loc) · 737 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
const path = require('path');
const childProcess = require('child_process');
const chokidar = require('chokidar');
const SERVER_PATH = path.join(process.cwd(), 'dist', 'server.js');
const start = () => {
console.log('starting new server');
const instance = childProcess.spawn('node', [SERVER_PATH]);
instance.stdout.on('data', (data) => console.log(data.toString()));
instance.stderr.on('data', (data) => console.error(data.toString()));
return () => {
console.log('shutting server down');
instance.kill();
};
};
let stop = start();
const restart = () => {
if (stop) {
stop();
}
stop = start();
}
const watcher = chokidar.watch(SERVER_PATH);
watcher.on('change', restart);