Skip to content

Instantly share code, notes, and snippets.

@roboshoes
Forked from webdesserts/Gulpfile.js
Last active November 11, 2015 20:08
Show Gist options
  • Save roboshoes/eb421ac6b7a9856b982c to your computer and use it in GitHub Desktop.
Save roboshoes/eb421ac6b7a9856b982c to your computer and use it in GitHub Desktop.
Automatically reload your node.js app on file change with Gulp (https://github.com/wearefractal/gulp).
var gulp = require( "gulp" );
var spawn = require( "child_process" ).spawn;
var node;
gulp.task( "server", function() {
if ( node ) node.kill();
node = spawn( "node", [ "app.js" ], { stdio: "inherit" } );
node.on( "close", function( code ) {
if (code === 8) {
gulp.log( "Error detected, waiting for changes..." );
}
} );
} );
gulp.task( "watch", function() {
gulp.watch( [ "./app.js" ], "server" );
} );
process.on( "exit", function() {
if ( node ) node.kill();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment