node.js,

Auto start pm2 apps on reboot

Jul 19, 2022 · 1 min read · Post a comment

PM2 is a process manager for Node.js that keeps apps up and running all the time. Unfortunately, this isn’t the case after a server instance reboots. So, let me show you how to do so.

Prerequisites

  • Node.js app
  • PM2
  • sudo privileges

Solution

Step 1. Invoke the startup script.

pm2 startup

Step 2. Verify.

systemctl status pm2-root

Note(s): pm2-root service name comes from the pm2 startup command output. It might not be the case for you. Example output snippet:

...
Command list
[ 'systemctl enable pm2-root' ]

Step 3. Save the pm2 app list.

pm2 save

Conclusion

Official PM2 startup script docs. Tried everything and nothing works? Let me know in the comment section below. On a side note, follow our official channel on Telegram.