Skip to content

Instantly share code, notes, and snippets.

@roboshoes
Forked from webdesserts/Gulpfile.js
Last active November 11, 2015 20:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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