Created
February 3, 2020 15:03
-
-
Save TomHumphries/cb3d5ee2a8170b6ada2d5c595451c87e to your computer and use it in GitHub Desktop.
Installing an auto-start Node.js service on a Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/ | |
| # https://medium.com/@simon_prickett/writing-a-systemd-service-in-node-js-on-raspberry-pi-be88d9bc2e8d | |
| # WorkingDirectory= | |
| # This is the path to the node.js server files. | |
| # If you don't add this in it will start the node server but try to look for files the server needs in the wrong folder. | |
| # This means you just get an error. | |
| # User=root | |
| # Personal experience - sometimes a service has file read/write access with User=pi, but sometimes not. | |
| # This doesn't seem to be a problem with User=root | |
| # You can't copy the service file using the ftp software. | |
| # The service file must be copied across to a "normal" area and then copied using: | |
| # sudo cp SERVICENAME.service /etc/systemd/system | |
| # Set the service up to run at start | |
| # sudo systemctl enable SERVICENAME.service | |
| # The service will run on start, but you can start it with: | |
| # sudo systemctl start SERVICENAME | |
| [Unit] | |
| Description=Demo Service | |
| After=network.target | |
| [Service] | |
| WorkingDirectory=/home/pi/Node/Demo | |
| ExecStart=/usr/local/bin/node /home/pi/Node/Demo/app.js | |
| Restart=on-failure | |
| Type=simple | |
| User=root | |
| Environment=PORT=3001 | |
| [Install] | |
| WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment