showing results for - "js implement hot reload"
Viktoria
05 Jun 2018
1const fs = require('fs')
2const child = require('child_process')
3
4// watch the target file
5const watcher = fs.watch('app.js')
6// create a child process for the target application
7let currentChild = child.fork('app.js')
8
9watcher.on('change', () => {
10  // we assure we have only one child process at time
11  if (currentChild) {
12    currentChild.kill()
13  }
14  // reset the child process
15  currentChild = child.fork('app.js')
16})
17