-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
How to cleanly exit nodemon #751
Comments
+1 Would like to know this as well. |
I was looking for this too. I found a workaround that might be helpful. If you exit with nodemon(...)
.on('error', function(code) {
if (code !== 2) {
console.log('Exited with error code: ', code);
}
}); if you don't want to or can't modify the child process it should be possible to run it like More details: #627 |
In tests, I cannot fully kill a nodemon process. nodemon(...).on('quit', function(){ this.reset() }) causes:
|
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. |
There has been some debate about removing the quit behaviour on exit code 2. So I would not recommend this technique, if you can find an alternative way. Edit: We actually did remove it! |
What is the state of this?
then I have to 1- Is it the expected behavior? |
@OoDeLally exit(2) is a crash code (from your script), so if you're catching the exit code inside your program and using exit 2, then nodemon is behaving exactly as it should. A clean exit code is 0, anything above is a bad exit code, and nodemon will catch it. Also, this issue was raised 3 years ago, so is unrelated to your original question. |
Thank you @remy. Is there a way to gracefully quit both If I understood @edwardhorsford right, this is exactly what he originally asked, so that is why I am posting here. Thank you |
Quitting nodemon is done using ctrl-c (if you're capturing stdin - then
it's ctrl-c twice). nodemon isn't automatically exited (wasn't sure if
that's what you were asking, but it shouldn't exit as it's meant for
development).
…On Mon, 9 Dec 2019 at 19:45, Pascal Heitz ***@***.***> wrote:
Thank you @remy <https://github.com/remy>. process.exit(0) indeed quit
nicely the nodejs process, but not nodemon.
Is there a way to gracefully quit both nodejs and nodemon at once, given
that I do capture stdin.
Thank you
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#751?email_source=notifications&email_token=AAADLBEZJ5T3LCRVVOZZXS3QX2N5FA5CNFSM4BYI5M7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGKNTLQ#issuecomment-563403182>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADLBHEFQGET3KKO3A36XTQX2N5FANCNFSM4BYI5M7A>
.
|
@remy it's some years since I raised this (and I no longer work for that bit of gov that used it). My use case was where the app's code has determined that nodemon should be quit. How should the app go about quitting nodemon? I think we had a situation where we asked the user a question in the terminal, and if they responded negatively, we then wanted to fully quit - at the time, we couldn't work out how to quit nodemon programatically. |
Darn, I didn't realise I was commenting on a 3 year old issue (I was doing it via email). Bottom line: unless you require nodemon as a dep, nodemon will not exit. This is expected behaviour. |
It may be an old issue but one that is still relevant. I run a number of daemons using nodemon and they don't have a command line. When I run directly under node I can tell the program to exit itself but how do I do that with nodemon? |
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 |
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:
|
I know it's an old issue. But it's not clear that it has been resolved. Note that I'm using Windows. In the meantime I've taken a different approach that doesn't depend on nodemon. |
It seems strange to me that nodemon doesn’t provide a clean, programmatic way to exit itself (in case it does, I can’t find it in the documentation). I’ve since been using |
Ok, what's the "..." guys? I can't seem to get this done using: nodemon = require("nodemon");
nodemon()
.on('error', function(code) {
if (code !== 2) {
console.log('Exited with error code: ', code);
process.exit(code)
}
});
process.exit(99) I get:
The surrounding code is lib/server.js in: https://github.com/poikilos/node-ticket-manager |
Starting the main script via a proxy seems to address the original question, how to make sure nodemon ends when the child process ends. // run-main.mjs
import nodemon from 'nodemon';
const mainArgs = process.argv.slice(2).join(' ');
nodemon(`<nodemon arguments> extensions/main.mjs ${mainArgs}`);
let ignoreExit = false;
nodemon.on('restart', () => {
ignoreExit = true;
}).on('exit', () => {
if(ignoreExit) {
ignoreExit = false;
return;
};
process.exit();
}); |
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. |
Unsure the exact reason but need to catch the exit event and call exit to ensure nodemon doesn't hang. Use a workaround as suggested in: remy/nodemon#751
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?
The text was updated successfully, but these errors were encountered: