Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to automatically restart a node server?

We are finishing development of a project, the client is already using it but occasionally some errors occur - crashing the server.

I know I could register a service as 'upstart' script on linux, in order to have my node service restart when it crashes.

But our server is running other stuff, so we can't restart it. Well, actually, while writing, I realize I have two questions then:

  • Will 'upstart' work without having to reboot? Something is just whispering yes to me :)
  • If not, what other option would I have to 'respawn' my node server when it crashes?
like image 688
transient_loop Avatar asked May 14 '13 16:05

transient_loop


People also ask

How do I restart NodeJS apps automatically?

Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.

How do I restart a NodeJS server?

If it's just running (not a daemon) then just use Ctrl-C . Where PID is replaced by the number in the output of ps . You could also use "killall -2 node", which has the same effect.

How do I restart node server after crash?

If your focus for automatic restart is an always running application, I suggest to use a process manager. Process manager, in general, handles the node process(es if cluster enabled), and is responsible for the process/es execution.


1 Answers

Yes, upstart will restart your process without a reboot.

Also, you should look into forever.

like image 197
Daniel Avatar answered Oct 08 '22 22:10

Daniel