Skip to content

Instantly share code, notes, and snippets.

@roboshoes
Forked from webdesserts/Gulpfile.js
Last active Nov 11, 2015
Embed
What would you like to do?
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