Raspberry Pi is capable to host a NodeJS server. We want to use node’s forever module to keep our node server running, even when system restarts.
Install forever and use the node app as root:
sudo -i npm install forever -g
Test run your nodeJS server app:
forever start /var/www/simple-server.js
Start node server app on boot
- To start editing run the following replacing the “pi” 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 pi -e
- It will ask you which editor you wish to edit with. Select nano.
- Once in the editor add the following line:
@reboot /usr/bin/sudo -u pi -H /usr/local/bin/forever start /var/www/simple-server.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 “pi” with your target username) to list the currently installed crons:
$ crontab -u pi -l
(Visited 10,405 times, 7 visits today)