nodemon: How to cleanly exit nodemon
We have a situation where we would like to completely quit node and nodemon.
We are using process.exit(0) to cleanly exit node. When this happens, we also want nodemon to quit. Instead it stays running and monitoring the directory.
How do we cleanly exit nodemon from within the app?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 13
- Comments: 19 (6 by maintainers)
I think the neatest way to implement this might be to let callers opt in to an exit code that would cause nodemon to quit. For example:
Would cause nodemon to close if the child process exits with code 222.
(An alternative, more readable option name might be
--die-on 222but-dis already taken, as are-eand-x)For anyone who stumbles on this thread in the future - there now appears to be an –exitcrash flag which will cause nodemon to exit if the child process crashes.
Firstly you’re commenting on an issue from 4 years ago (and closed).
Secondly, you can use the OS to do this without having to add to nodemon:
Starting the main script via a proxy seems to address the original question, how to make sure nodemon ends when the child process ends.
This issue has been automatically marked as idle and stale because it hasn’t had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing ❤️
I was looking for this too. I found a workaround that might be helpful.
If you exit with
process.exit(2)it will cause nodemon also to exit. Nodemon will print stack trace so you might also hook intoerrorevent to make it clean, e.g.:if you don’t want to or can’t modify the child process it should be possible to run it like
your_command || exit 2to make it work.More details: https://github.com/remy/nodemon/issues/627