A Compact Guide That Explains PM2 Feature
Posted By : Arun Kataria | 30-Apr-2018
PM2 is a Node process manager, Which is widely used in producation environment, And it is an open-source Node process manager. Used by many developers around the World.
With just a one line command and your server is alive for forever, And it will auto-restart also when it shutdown by some error. All the running process are managed by PM2. You can view each running process and there log by there process id, And can perfrom action on a paticular process by their process id. PM2 also sacle your applicaiton by serveral child process creating for though have the same server port. You can also see the CPU usage, memory used request and many more thins in that. It will manage most of the thing of server.
It will solve many problems few are:
1) It will restart the application if it
2) It will help you by restarting your node application as a service every time you restart a server. There are many ways to do this, but pm2 makes it easier, and it has some added flexibility.
3) It will keep a log for your unhandled exception - in that case, in a file at /home/safeuser/.pm2/logs/app-err.log.
Command to install PM2:
sudo npm install pm2 -g
Command to start PM2:
pm2 start <name_of_the_main_file>
Exapmle:
pm2 start app.js
Command to run your application as a service:
sudo env PATH=$PATH:/usr/local/bin pm2 startup -u safeuser
Please note, you can't use
pm2 monit
Command to list all process:
pm2 list
To stop PM2:
pm2 stop 0 # Stop specific process id
To restart PM2:
pm2 restart 0 # Restart specific process id
To remove
pm2 delete 0 # Will remove process from pm2 list by id
pm2 delete all # Will remove all processes from pm2 list
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Arun Kataria
Arun has good skills in AngularJS, NodeJS, MongoDB and many more. He is highly motivated which allow him to strive for proficiency when accomplishing assigned duties. He is an excellent team operative.