Run Node.js Apps with Forever on Ubuntu Server

PM2 is a great process manager for Node.js apps.  I have been using PM2 for a while, but lately it gave up on me – it refused to start one of my Node.js apps.  I tested the app and did not find any problems with it: it started up and ran ok when I was using node command.  So, I started looking for solutions alternative to PM2.  I ended up using forever, forever-service, and crontab to run my Node.js app continuously.

First I installed forever
[sudo] npm install -g forever

Then I installed forever-service
[sudo] npm install -g forever-service

Next I switched into my app’s directory and ran the following command that created a service
[sudo] forever-service install myservice --script main.js
where myservice is an arbitrary name of the service and main.js main entry point script of your app.

After that I started my newly created service
[sudo] service myservice start

Unfortunately, after my server rebooted I noticed that my created service did not start back up unlike apache2, for example. So finally I put service start command in crontab
crontab -e
In the end of the file I placed
@reboot sudo service myservice start

Using this process I am able now to continuously run my Node.js apps.