- To start editing run the following replacing the "testuser" with your desired runtime user for the node process. If you choose a different user other then yourself, you will have to run this with sudo.
$ crontab -u testuser -e
-
If you have never done this before, it will ask you which editor you wish to edit with. I like vim, but will recommend nano for ease of use.
-
Once in the editor add the following line:
@reboot /usr/local/bin/forever start /your/path/to/your/app.js
-
Save the file. You should get some feedback that the cron had been installed.
-
For further confirmation of the installation of the cron, execute the following (again replacing "testuser" with your target username) to list the currently installed crons:
$ crontab -u testuser -l
-
Note that in my opinion, you should always use full-paths when executing binaries in cron. Also, if the path to your forever script is not correct run which forever to get the full path.
-
Given that forever calls node, you may also want to provide the full path to node:
@reboot /usr/local/bin/forever start -c /usr/local/bin/node /your/path/to/your/app.js