Node.js › Deployment & Process Managers (PM2)
How do you configure PM2 to automatically restart your Node.js application after a server reboot?
IntermediateAnswer
PM2's 'startup' command generates and configures a system-specific init script (systemd on most modern Linux distributions) that starts PM2 itself automatically on system boot; combined with 'pm2 save' (which persists the current list of running processes to a dump file), PM2 will automatically restore and restart every previously running application after the server reboots, without any process being lost.
pm2 startup # generates and prints a system-specific command to run
# (run the printed command, e.g. with sudo, to actually register the startup script)
pm2 save # saves the currently running process list
# After a reboot, PM2 automatically restores everything from this saved listReal-world example A production server that was manually restarted for a security patch came back up with the Node.js API not running at all until an engineer noticed and manually started it again; running 'pm2 startup' and 'pm2 save' beforehand ensures the application resumes automatically on any future reboot without manual intervention.