1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Making a node.js application run permanently with on a Cloud Server
This guide explains how to make a node.js application run permanently, even after a Cloud Server restart.
This information is shared for informational purposes only, and our support team cannot assist you in the event you have a problem following these instructions. Find out more
1. Install the node.js application
- Install the desired node.js application (e.g.: Ghost, Laverna, etc.) by following the instructions from its publisher.
2. Install Forever (*)
- log in under SSH to the hosting concerned (help)
- run the following command:
npm install forever -g
3. Create a script to run the node.js application in the event of a shutdown
- create the script "start.sh" at the root of the hosting, with the following contents (don't forget to adapt the path of the node.js application) :
if ! forever list | grep -q '/web/app.js' ; then
forever start ~/web/app.js -m 1
- make the script executable (CHMOD 755):
chmod 755 start.sh
4. Create a CRON to execute the script every minute
- carry out the following SSH command:
- add the following directive via the text editor vi that opens automatically (don't forget to adapt the path of the script; the SSH pwd command displays the path of the current folder):
* * * * * /home/clients/XXXX/start.sh 1>/dev/null
You may therefore consider using pm2 as it works perfectly. It is easy to manage a cluster with and to restart applications when they crash, etc. It is very practical for following logs, making a yml file to launch all the node servers wit their respective configurations... What is more, pm2 can be connected to the keymetrics monitoring dashboard which allows you (by opening the right ports) to restart node servers from the dashboard and receive notifications in the event of a problem, etc.