Essential commands pm2

tiago123456789

Tiago Rosa da costa

Posted on February 26, 2021

Essential commands pm2

Essential commands pm2

I think that before we need to understand what is pm2? Pm2 is one tool that allows management of the process, case the process stops running the pm2 make restart the process, another thing interessent is that you can look at logs of the process to understand error that occurs.

Command to install pm2:

 npm i -g pm2
Enter fullscreen mode Exit fullscreen mode

Command above install the pm2 globally

Command listing the processes running in pm2:

 pm2 list
Enter fullscreen mode Exit fullscreen mode

Command to execute one process with the pm2:

pm2 start path_script_js
Enter fullscreen mode Exit fullscreen mode

Command to execute one process and specific name to the process with the pm2:

pm2 start path_script_js --name=name_process
Enter fullscreen mode Exit fullscreen mode

Command to execute one process in cluster mode with pm2:

pm2 start path_script_js -i max
Enter fullscreen mode Exit fullscreen mode

The command above init script and the parameter -i max will put this process the same as how many cpu core of the machine is running the application. It's to prevent that you have to implement it manually using a cluster module of node.js for creating child processes starting the parent process. It’s one strategy used to better performance in node.js applications.

Command to stop all the processes in the pm2:

  pm2 stop all
Enter fullscreen mode Exit fullscreen mode

Command to stop one process in the pm2:

pm2 stop id_process
Enter fullscreen mode Exit fullscreen mode

Command to delete all the processes in the pm2:

pm2 delete all
Enter fullscreen mode Exit fullscreen mode

Command to delete one process in the pm2:

pm2 delete id_process
Enter fullscreen mode Exit fullscreen mode

Command to see logs one process in the pm2:

 pm2 logs id_process
Enter fullscreen mode Exit fullscreen mode

Command to restart one process in the pm2:

  pm2 restart id_process
Enter fullscreen mode Exit fullscreen mode

Command to restart all the processes in the pm2:

 pm2 restart all
Enter fullscreen mode Exit fullscreen mode

Command to save the processes in the pm2:

pm2 save
Enter fullscreen mode Exit fullscreen mode

The command above is helpful, because will create one backup file with the processes that are running in pm2, case have that make reboot the machine the pm2 will use the backup file to recreate the processes.

πŸ’– πŸ’ͺ πŸ™… 🚩
tiago123456789
Tiago Rosa da costa

Posted on February 26, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related