In our last post, we covered how to install Node.js and nginx on Ubuntu. We had Node.js running in the background with a terminal command…but what if this process got interrupted or stopped for some reason? Then our application would stop working. We should have something in place that would start up our Node app if it ever stopped working. We should also have something in place that would start up our Node app when we restart the server. Let’s explore how we would take of these issues.
- You should already have Node.js installed. Check the previous post if you need help doing so. (It’s simple and laid out for you)
- Then go to the folder when you have your node app installed and install Forever (which will try to make you Node app run ‘forever’). The first command install forever globally and the second command keeps your app running forever:
npm install forever -g forever start --spinSleepTime 10000 example.js
- Then to cause your app to start when you restart your server implement the steps found in this tutorial:
Now our Node app should stay up! If you want to stop your app that is running, you can enter in something like “forever stopall” or “forever stop example.js”.