PM2 Node.js Library to Run Node Applications Forever With Built in Load Balancer Full Tutorial For Beginners

You are currently viewing PM2 Node.js Library to Run Node Applications Forever With Built in Load Balancer Full Tutorial For Beginners

 

Welcome folks today in this blog post we will be talking about pm2 node.js library to run node.js applications forever without any downtime. It also have a built in load balancer in tthe pm2 library.

 

 

Get Started

 

 

In order to get started you need to install pm2 library globally inside your system or server

 

npm i -g pm2

 

-g is a flag inside npm command to install the module globally inside your system or server

 

 

Advantages

 

 

So now coming to advantages of pm2

 

You can run node.js applications forever without having to run server or system all the time

 

 

Starting Node Apps with PM2

 

 

Now to run a app.js node.js server with pm2 you need to execute the below command

 

pm2 start app.js

 

Now after executing it then it will start all the node.js processes and applications and the screenshot looks like this

 

 

 

 

 

Stopping Node.js Apps with pm2

 

 

Now to stop a node.js app app.js with pm2 you need to execute the following command shown below

 

pm2 stop app.js

 

And now if you execute the command you will see the following screenshot below

 

 

 

 

 

 

Managing Node.js Apps

 

 

 

Now to manage node.js apps in pm2 we need to execute the following command

 

Now to get list of all node.js processes we need to execute the following command

 

pm2 list

 

 

 

 

 

Other Useful Commands

 

 

Now it also supports other useful commands like

 

to stop node.js app

 

pm2 stop index.js

 

To Delete Node.js App

 

pm2 delete index.js

 

to restart node.js app

 

pm2 restart index.js

 

To have more details on a specific application:

pm2 describe index.js

To monitor logs, custom metrics, application information:

pm2 monit index.js

Zero Downtime Reload

Hot Reload allows to update an application without any downtime:

pm2 reload all

 

Log Management

To consult logs just type the command:

 

pm2 logs

 

 

Leave a Reply