Add an entry in systemd for your service, adding the following file to /lib/systemd/system/steinway.service
.
[Unit]
Description=Example node JS app
Documentation=https://www.example.com
After=network.target
[Service]
Environment=NODE_PORT=8080
Type=simple
User=node
ExecStart=/usr/bin/npm --prefix /srv/steinway
Restart=on-failure
[Install]
WantedBy=multi-user.target
Systemctl useful commands:
# check if service is already running
$ sudo systemctl status steinway
# control the lifecycle of the service
$ sudo systemctl start steinway
$ sudo systemctl restart steinway
$ sudo systemctl stop steinway
# enable the service to start on boot
$ sudo systemctl enable steinway
# disable the service from starting on boot
$ sudo systemctl disable steinway
More info at:
https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/
https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-2/