remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.13k stars 1.72k forks source link

Restart app on specific exit code #2197

Closed mStirner closed 2 months ago

mStirner commented 2 months ago

I wanted to know if its possible to restart a app with nodemon when the app exit/returns with a specific exit code. Nodemon waits for changes, when a app crashes or exit successful.

I want to add a "restart" function in my app. This is no problem when the app is started with systemd or put into a container.

But while in "development mode" it would also be nice to have this option. So i thought if i start nodemon --restart-code=321 app.js and my app exists with code 321, nodemon starts the app without waiting for any changes.

Note: This feature must not be implemented in nodemon itself if you know a unix way to do this. As long as i can put it into package.json and use it with npm run dev.

remy commented 2 months ago

Using node as a required module, you can control the process and decide how shutdown is handled (I believe).

mStirner commented 2 months ago

Can you provide please a example/dummy code? Not sure what you mean/how that works. (Or at least more context)

remy commented 2 months ago

Have a look at the docs (directory or the wiki) for the required mode (I'm on mobile at the moment so can't provide an example, and I can rely on instantly forgetting things by the time I'm back to my desktop tomorrow!)