If you reboot your Raspberry Pi, and you want your Node application to be executed on startup, you can install it as a service and specify that it should always run when restarted.

Create a .service file under /etc/systemd/system. For my outlet service, I created /etc/systemd/system/outlet.service and added the following:

[Service]
WorkingDirectory=/home/pi/Documents/Repos/outlet-device
ExecStart=/usr/local/bin/npm start
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=notell
User=root
Group=root
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

Helpful commands

sudo systemctl enable outlet - enables the service which will start on reboot

sudo systemctl disable outlet - disables the service, preventing it from starting on reboot

sudo systemctl start outlet - starts the service immediately

sudo systemctl stop outlet - stops the service, but the service will restart on reboot if it is still enabled