Running Node.js app as a service forever


When you start a Node.js server simply using node app.js, the server stops as soon as the shell session is killed. But if you want to keep you server running, as a server would naturally should, you need some way to keep the server proc alive.

Forever is seemingly a popular choice for running a server, as the name suggests, forever; or technically as long as you want.

While trying to install Forever, globally, via npm, it was complaining about the version number of inherits. So I did:

sudo npm install inherits -g

and then did:

sudo npm install -g forever

You are ready to run a nodejs server forever. Hence, do this:

 forever start --minUptime 1000 --spinSleepTime 1000 app.js

To make sure your new service is up

forever list

And if you want to stop, use

forever stop <PID/PID>

One thought on “Running Node.js app as a service forever

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.