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
Command above install the pm2 globally
Command listing the processes running in pm2:
pm2 list
Command to execute one process with the pm2:
pm2 start path_script_js
Command to execute one process and specific name to the process with the pm2:
pm2 start path_script_js --name=name_process
Command to execute one process in cluster mode with pm2:
pm2 start path_script_js -i max
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
Command to stop one process in the pm2:
pm2 stop id_process
Command to delete all the processes in the pm2:
pm2 delete all
Command to delete one process in the pm2:
pm2 delete id_process
Command to see logs one process in the pm2:
pm2 logs id_process
Command to restart one process in the pm2:
pm2 restart id_process
Command to restart all the processes in the pm2:
pm2 restart all
Command to save the processes in the pm2:
pm2 save
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.
Top comments (0)