Skip to content

Instantly share code, notes, and snippets.

@andrewfaria
Created April 3, 2014 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewfaria/9957058 to your computer and use it in GitHub Desktop.
Save andrewfaria/9957058 to your computer and use it in GitHub Desktop.
Beat the pesky node forever -w flag and only restart one file with this
var fs = require('fs'),
exec = require('child_process').exec,
child,
restarting = false
function watch() {
restarting = false
fs.watch('./server.js', function(e, file) {
console.log(e + ' : ' + file)
restart()
})
}
function restart() {
if(restarting === false) {
restarting = true
child = exec('forever restart server.js', function(err, stdout, stderr) {
setTimeout(function() {
watch()
},1000)
})
}
}
watch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment