Essential PM2 Commands for Managing Node.js Apps
At Prism ICT, we run multiple Node.js microservices in production. To keep them stable and easily manageable, we rely on PM2, a powerful production process manager. Whether you’re deploying a small app or managing dozens of services, PM2 simplifies your workflow with tools to start, monitor, and auto-restart your apps.
In this guide, weโll walk you through essential PM2 commands every developer and sysadmin should know.
โ 1. Installation
Install PM2 globally:
npm install -g pm2
๐ข 2. Start an Application
Start your app with:
pm2 start app.js
With a name:
pm2 start app.js --name prism-api
โป๏ธ 3. Restart an App
pm2 restart prism-api
Or restart all:
pm2 restart all
๐ด 4. Stop or Delete an App
Stop one:
pm2 stop prism-api
Delete one:
pm2 delete prism-api
Delete all:
pm2 delete all
๐ 5. View Running Apps
pm2 list
Detailed info:
pm2 show prism-api
๐ 6. View Logs
All logs (stdout + stderr):
pm2 logs
Only error logs:
pm2 logs --err
Specific app logs:
pm2 logs prism-api
Tail last 100 lines:
pm2 logs --lines 100
๐ 7. Auto Startup on Server Reboot
Generate startup script:
pm2 startup
Then follow the printed instructions, usually involves:
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u your_user --hp /home/your_user
Save process list:
pm2 save
Now your apps will start on server reboot.
๐พ 8. Save and Load App List
Save current state:
pm2 save
Reload from saved state:
pm2 resurrect
๐ 9. Reload App Without Downtime
For zero-downtime reloads (especially for APIs):
pm2 reload prism-api
๐ฆ 10. Deploy with Ecosystem File
Create config:
pm2 init
Then edit ecosystem.config.js and deploy with:
pm2 start ecosystem.config.js
๐งน 11. Clear Logs
pm2 flush
๐ง Final Tips from Prism ICT
- Monitor your apps with PM2 Plus (pm2.io)
- Keep logs clean to save disk space
- Always run
pm2 saveAfter making changes - Automate deployment with ecosystem files
๐ At Prism ICT, PM2 has become a vital part of our infrastructure for Node.js services. Whether you’re handling APIs, background workers, or cron jobs โ PM2 keeps your processes alive and healthy.
Let us know if you’d like a PDF version of this guide or an internal cheat sheet for your team!