Created
April 3, 2014 15:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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