PM2 cheat sheet | PM2 commands | PM2 tutorial

pm2 logo

PM2 (Process Manager):

PM2 is process manager for Node.JS apps, when I want to keep node app to run in 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 lets share this as cheatsheet with all of you might be this can be useful for all of you.

PM2 Cheatsheet:

Start Proccess:

pm2 start server.js --name crudapp

It will start server.js app with name as crudapp.


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 server stops.


pm2 start server.js --no-vizion
It will skip 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 ith process.


Stop Process:

pm2 stop i 
It will  stop  ith number process.

pm2 stop all 
It will  stop  all proccess running on the server.

Restart/ Reload Process: 

pm2 restart i 
It will  restart  ith number process.

pm2 restart all 
It will  restart  all proccess running on the server.

pm2 reload i 
It will  reload  ith number process.

pm2 reload all 
It will  reload  all proccess 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 proccess:

pm2 list
It will  display all the available proccesses.

pm2 monit
It will  monitor all the available proccesses.

pm2 jlist
It will  show all processes in raw JSON.

pm2 prettylist
It will  show all processes in beautified JSON.


Delete Proccess:

pm2 delete i 
It will  delete or remove 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.
PM2 cheat sheet | PM2 commands | PM2 tutorial PM2 cheat sheet | PM2 commands | PM2 tutorial Reviewed by JSDevLife on Friday, May 31, 2019 Rating: 5

No comments:

Powered by Blogger.