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?

Yes, upstart will restart your process without a reboot.

Also, you should look into forever.

you can also use nodemon .

npm install -g nodemon

nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application.


Edit

sudo nodemon server.js