Tools: systemd for Node.js Developers — Auto-Restart, Logging, and 24/7 Uptime
Why systemd?
The Service File
Key Features
Auto-Restart
Logging
Commands
vs PM2
Production Setup PM2, forever, and nodemon are great for development. But for production on a Linux VM, systemd is already there and does everything you need. Restart=always + RestartSec=5 means if your app crashes, it restarts in 5 seconds. No log rotation config needed — journald handles it. I run a 4,500-line trading bot on Oracle Cloud free tier using systemd. Been up for months with zero manual intervention. Deploy guide: dev.to/tatelyman/deploy-any-nodejs-app-247-for-free-on-oracle-cloud Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse
# /etc/systemd/system/myapp.-weight: 500;">service
[Unit]
Description=My Node.js App
After=network.target [Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/my-app
ExecStart=/usr/bin/node app.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
StandardOutput=journal
StandardError=journal [Install]
WantedBy=multi-user.target
# /etc/systemd/system/myapp.-weight: 500;">service
[Unit]
Description=My Node.js App
After=network.target [Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/my-app
ExecStart=/usr/bin/node app.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
StandardOutput=journal
StandardError=journal [Install]
WantedBy=multi-user.target
# /etc/systemd/system/myapp.-weight: 500;">service
[Unit]
Description=My Node.js App
After=network.target [Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/my-app
ExecStart=/usr/bin/node app.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
StandardOutput=journal
StandardError=journal [Install]
WantedBy=multi-user.target
journalctl -u myapp -f # Live logs
journalctl -u myapp --since today # Today's logs
journalctl -u myapp -n 100 # Last 100 lines
journalctl -u myapp -f # Live logs
journalctl -u myapp --since today # Today's logs
journalctl -u myapp -n 100 # Last 100 lines
journalctl -u myapp -f # Live logs
journalctl -u myapp --since today # Today's logs
journalctl -u myapp -n 100 # Last 100 lines
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start myapp # Start
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">stop myapp # Stop
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart myapp # Restart
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status myapp # Check -weight: 500;">status
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable myapp # Start on boot
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start myapp # Start
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">stop myapp # Stop
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart myapp # Restart
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status myapp # Check -weight: 500;">status
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable myapp # Start on boot
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start myapp # Start
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">stop myapp # Stop
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart myapp # Restart
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status myapp # Check -weight: 500;">status
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable myapp # Start on boot