Skip to content

Restart Node.js automatically

bogdangorescu edited this page Jan 1, 2015 · 7 revisions

Hi, I lost connection to mongolabs a few times which caused node to crash so I wanted node to auto restart node if this happens again. I decided to use a tool called forever to restart node if it crashes. Here is how to implement it: (**note some hosting services already use forever but in some cases they don't)

These steps where tested with Linux and Windows.  It is as simple as ABC
1. A) At the command prompt type:  sudo npm install forever -g
2. B) Once it is installed type: forever start server.js
3. C) To see if it is running type:  forever list

The github respository for forever is: https://github.com/nodejitsu/forever  


+++
Hi,
I found an ALTERNATIVE way to autorestart the server, which gives more control and a web interface to see the status. It's also pretty easy to install and use:
1. Type: sudo npm install -g pm2
2. cd into the nightscout directory and type: pm2 start server.js
3. To see if it's running, use the web interface (same as your webserver address and port 9615), or pm2 status