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!)

example.txt
[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.target

Replace:

Then enable start at boot & start right now: (Remember to replace myapplication by the name of the service file you chose!)

example.sh
sudo systemctl enable --now myapplication

Start by

example.sh
sudo systemctl start myapplication

Restart by

example.sh
sudo systemctl restart myapplication

Stop by

example.sh
sudo systemctl stop myapplication

View & follow logs:

example.sh
sudo journalctl -xfu myapplication

View logs in less:

example.sh
sudo journalctl -xu myapplication

 


Check out similar posts by category: Linux