PM2 |
PM2 (Process Manager):
PM2 is a process manager for Node.JS apps when I want to keep node app to run in the background mostly use pm2 for it.
I wanted to understand all its commands and its use so I went through its document, and write down some useful commands, then I thought let’s share this as cheatsheet with all of you might be this can be useful for all of you.
PM2 Cheatsheet:
Start-Process:
pm2 start server.js --name crudapp
It will start server.js app with name as crud app.
pm2 start server.js --no-daemon
It will run pm2 daemon in the foreground if it doesn’t exist already.
pm2 start server.js --no-autorestart
It will not auto restart if the server stops.
pm2 start server.js --no-vizion
It will skip the versioning control mode.
pm2 start server.js -i 0
It will start maximum processes with LB depending on available CPUs.
pm2 start all
It will start all existing process and restart if already running.
pm2 describe i
It will display all the details for the ith process.
Stop-Process:
pm2 stop i
It will stop the ith number process.
pm2 stop all
It will stop all process running on the server.
Restart/ Reload Process:
pm2 restart i
It will restart the ith number process.
pm2 restart all
It will restart all process running on the server.
pm2 reload i
It will reload the ith number process.
pm2 reload all
It will reload all process running on the server.
Restart VS Reload:
With reload, pm2 restarts all processes one by one, always keeping at least one process running.
Listing the process:
pm2 list
It will display all the available processes.
pm2 monit
It will monitor all the available processes.
pm2 jlist
It will show all processes in raw JSON.
pm2 prettylist
It will show all processes in beautified JSON.
Delete Process:
pm2 delete i
It will delete or remove the ith number process from pm2 list.
pm2 delete all
It will delete or remove all processes from pm2 list.
PM2 Logs:
pm2 logs
It will show all processes logs in streaming.
pm2 flush
It will empty all processes log files.
pm2 reloadLogs
It will reload all processes logs.
Rotational Logs:
If you want rotational logs then you can install pm2 dependency to use it.
pm2 install pm2-logrotate
You can configure as per your requirements.
pm2 set pm2-logrotate:
This is basic commands for logrotate.
You can find more details for logrotate on this Github link
If you have more commands then please comment here so I can update it.
Thanks.