Wednesday, 10 May 2017

docker node app always crashes on file change using nodemon

I am using the latest version of docker and the latest node image. I have a gulpfile that starts a nodemon process. I am using the --inspect flag to indicate I want to use the experimental chrome dev tool debugger. But when I make a file change it nodemon picks it up and restarts the process but crashes.

Here is my gulp task:

gulp.task('start:dev', done => {
  let started = false;
  nodemon({
    script: path.join(__dirname, 'index.js'),
    ext: 'js json',
    nodeArgs: ['--inspect=0.0.0.0:9229'],
    watch: path.join(__dirname, 'express'),
    legacyWatch: true
  })
  .on('start', () => {
    // to avoid nodemon being started multiple times
    if (!started) {
      setTimeout(() => done(), 100);
      started = true;
    }
  });
});

And here is the error:

Starting inspector on 0.0.0.0:9229 failed: address already in use

If I change the --inspect flag to be --debug it works like a charm.

I am guessing is that the restart process is too fast for the --inspect to release its port. If I make another file change it does work and restarts normally. Probably since it had time to release the port.

I have tried using a delay on nodemon but I'd rather not. I would like quick restarts. And I have tried using to events, like, restart and exit, to wait for a few seconds and then restart the whole gulp task. But that was temperamental and again I want quick restarts without having to hack together something.

Right now I just switched back to --debug but that is deprecated in the latest V8. They are recommending to use --inspect.

Maybe the only way is to lock down my version of node?

Any suggestions?



via Andrew Bliss

No comments:

Post a Comment