Ben Aston Ben Aston - 2 years ago 118
Node.js Question

Preventing the process from exiting when running a gulp task (so a server remains up)

I have a gulp task that starts a server:

gulp.task('my-task', ['start-server'], function() {});

The gulp task
registers a listener:

process.on('exit', function () {

But, I want the server to remain open. A bit like a
task stays "open".

Currently, AFAICT, the Node.js process running the gulp task, exits upon completion of the gulp task and takes down the server with it.

How can I avoid the process exiting and taking the server down with it?

Answer Source

That's what gulp-nodemon was meant to do:

Example implementation:

gulp.task('develop', function () {
  nodemon({ script: 'server.js'
          , ext: 'html js'
          , ignore: ['ignored.js']
          , tasks: ['lint'] })
    .on('restart', function () {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download