Systemd Unit for autostarting NodeJS application (npm start)
This systemd unit file autostarts your NodeJS service using npm start. Place it in /etc/systemd/system/myapplication.service (replace myapplication by the name of your application!)
myapplication.service
[Unit]
Description=My application
[Service]
Type=simple
Restart=always
User=nobody
Group=nobody
WorkingDirectory=/opt/myapplication
ExecStart=/usr/bin/npm start
[Install]
WantedBy=multi-user.targetReplace:
/opt/myapplicationby the directory of your application (wherepackage.jsonis located)User=nobodyandGroup=nobodyby the user and group you want to run the service as- Optionally you can add a custom decription instead of
Description=My application
Then enable start at boot & start right now: (Remember to replace myapplication by the name of the service file you chose!)
enable_myapp.sh
sudo systemctl enable --now myapplicationStart by
start_myapp.sh
sudo systemctl start myapplicationRestart by
restart_myapp.sh
sudo systemctl restart myapplicationStop by
stop_myapp.sh
sudo systemctl stop myapplicationView & follow logs:
journalctl_follow.sh
sudo journalctl -xfu myapplicationView logs in less:
journalctl_less.sh
sudo journalctl -xu myapplicationCheck out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow