remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development

Home Page:http://nodemon.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restart app on specific exit code

mStirner opened this issue · comments

  • nodemon -v: 3.0.3
  • node -v: 20.11.0
  • Operating system/terminal environment: Ubuntu Unity 23.10

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.

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

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

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!)