Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp-watch & gulp-nodemon #77

Closed
ghost opened this issue Jul 3, 2015 · 11 comments
Closed

gulp-watch & gulp-nodemon #77

ghost opened this issue Jul 3, 2015 · 11 comments

Comments

@ghost
Copy link

ghost commented Jul 3, 2015

I'm using gulp-watch package that starts also gulp-nodemon, like so:

gulp.task('gulp-nodemon', function() {
  nodemon({
    script: 'test/fixtures',
    watch: 'test/fixtures',
    ext: 'js json'
  });
});

gulp.task('watch', ['gulp-nodemon'], function() {
  gulp.start('browser-sync');
  watch('app/**/*', function() {
    browserSync.reload();
  });

However, when I quit the gulp watch command with Ctrl + c, then nodemon process is still running. Is there a way how to cleanly exit the process?

@scottseeker
Copy link

I have the same issue.

@eliot-akira
Copy link

Same here. After quitting gulp with Ctrl + c, the process continues to run - and when I enter any key on the bash command line, the process finally ends with an error:

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: read EIO
  at exports._errnoException (util.js:837:11)
  at TTY.onread (net.js:544:26)

I've tried different methods to prevent this, but so far no success. The only workable way I found was to run nodemon and gulp separately. I'll be checking back on this ticket to see if anyone finds a better solution.


Edit: In my case, the issue was not with gulp-nodemon but a mistake in the setup. I had a watch task manually reloading browser-sync, when it was already watching the same files.

@mshwery
Copy link

mshwery commented Nov 9, 2015

same

@eliot-akira
Copy link

For me, the following finally solved this issue:

var monitor = nodemon(options);

process.once('SIGINT', function() {
  monitor.once('exit', function() {
    process.exit();
  });
});

Without this handler, the process doesn't exit on Ctrl+C and then throws an error on TTY.onread. With it, it exits clean. I have several watch tasks including nodemon and browser-sync, so your mileage may vary.

@mshwery
Copy link

mshwery commented Nov 10, 2015

@eliot-akira what is process for you in this closure? nvm

@theverything
Copy link

Thank you for this thread I've been having this issue for the last couple weeks and couldn't figure out why.

I used a modified version of @eliot-akira fix. Which seems to have removed the error.

gulp.task('server', function () {
  nodemon({
    script: './server.js',
  })
  .once('exit', function () {
    console.log('Exiting the process');
    process.exit();
  });
});

@PeterPanen
Copy link

@theverything
It seems here that the nodemon exit event also gets triggered when nodemon restarts, due to file changes.

Listening for SIGINT like @eliot-akira mentions seems to work better for now at least.

@glortho
Copy link

glortho commented Dec 22, 2015

@eliot-akira thank you!

@bavellone
Copy link

@theverything Just what I was looking for. Thanks!

@ColemanGariety
Copy link
Owner

I think this is a duplicate of #33.

@jwickens
Copy link

jwickens commented Feb 6, 2017

The following works pretty well for me:

    nodemon.on('start', () => {
        debug('nodemon has started app');
    }).on('quit', () => {
        debug('nodedmon has quit');
        process.exit();
    }).on('restart', function(files) {
        debug('App restarted due to: ', files);
    });

jwickens added a commit to jwickens/nodemon that referenced this issue Feb 6, 2017
I kept getting this annoying problem after following this tutorial which is best described in this gulp thread. ColemanGariety/gulp-nodemon#77. I'm not using gulp but the problem is the same. By adding process.exit() on nodemon quit the problem goes away smoothly.

Maybe add this process.exit() hint in the docs here?
remy pushed a commit to remy/nodemon that referenced this issue Sep 4, 2017
I kept getting this annoying problem after following this tutorial which is best described in this gulp thread. ColemanGariety/gulp-nodemon#77. I'm not using gulp but the problem is the same. By adding process.exit() on nodemon quit the problem goes away smoothly.

Maybe add this process.exit() hint in the docs here?
Izhaki added a commit to Izhaki/nodemon-webpack-plugin that referenced this issue Dec 12, 2017
Based on
ColemanGariety/gulp-nodemon@8ee28a46a9f335d9ba
bf0131fde29b646cc621c3
Notes:
    - ColemanGariety/gulp-nodemon#77 work on
Mac but not Windows.
    - Not listening to SIGTERM, like
https://github.com/webpack/webpack-dev-server/blob/93cb3dc600e6c547cec75
80ace4bf4a56cf2fe98/bin/webpack-dev-server.js
    - Also consider https://github.com/sindresorhus/exit-hook and it’s
active fork.
Izhaki added a commit to Izhaki/nodemon-webpack-plugin that referenced this issue Dec 12, 2017
* Fix: Nodemon not stopping on windows upon Ctrl-C

* Refactor: change process.exit comments.

Based on
ColemanGariety/gulp-nodemon@8ee28a46a9f335d9ba
bf0131fde29b646cc621c3
Notes:
    - ColemanGariety/gulp-nodemon#77 work on
Mac but not Windows.
    - Not listening to SIGTERM, like
https://github.com/webpack/webpack-dev-server/blob/93cb3dc600e6c547cec75
80ace4bf4a56cf2fe98/bin/webpack-dev-server.js
    - Also consider https://github.com/sindresorhus/exit-hook and it’s
active fork.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants