pm2 Quick Start
I couldn't find a single consolidated place that explains how to setup pm2 from scratch (assuming you've already installed Node.js), and their own "quick start" didn't help. I was finally able to piece together how to get it working.
- Install pm2:
npm i -g pm2 - Configure pm2 to restart processes on reboot:
pm2 startup - If that command prints a command to run, run it.
cdto wherever your script is.- Run the script with pm2:
pm2 start <command> -- <args>pm2 start npm -- startpm2 start node -- index.jspm2 start npx -- tsx index.ts
- Verify that it is running with
pm2 list - Run
pm2 save
Now if you reboot your system, pm2 should automatically start itself and the script you ran!