Skip to content

Restart Node.js automatically

Daniel edited this page Jul 22, 2014 · 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 this case 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