I am running a Linux VPS which is running different applications, some of them are NodeJS applications. At home I’m running them with docker but since docker does not work on my VPS I had to figure out another way, I have used forever and crontab before so this is how I did it.
Installation of Node and forever.
$ sudo apt-get install nodejs
$ sudo npm install forever -g
Edit Crontab
To start editing crontab run the following and replace patrik with your desired runtime user for the node process.
If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u patrik -e
If this is the first time you have used crontab you will get a question about which editor you wish to edit with. When in editor you need to add your application (forever with parameters start and the path to your application js file). (Double check your paths not all distros use the same path)
@reboot /usr/share/forever start /your/path/to/your/app.js
When you save your file you should get feedback that the cron has been installed.
If you want to confirm the installation you can execute the following command which lists all the installed crons
$ crontab -u patrik -l
If you have problems with forever not finding node you can provide the full path to node by adding -c /path/to/node
@reboot /usr/local/bin/forever start -c /path/to/node /your/path/to/your/app.js