30.04.20244 min read

Node.js PM2 Orchestration Explained

By Mirza Leka

Enhance Node.js apps effortlessly with process management, self-recovery, scaling, monitoring, and logging.

PM2 and Node.js orchestration

Learn how to tackle server crashes and high traffic with PM2. Enhance Node.js apps effortlessly with process management, self-recovery, scaling, monitoring, and logging.

Meet Joe.

Joe is a Node.js developer who has just created an awesome web application. He hosted a virtual machine, started an app with node app.js, made himself a drink, and sat back to welcome the happy fans.

A few hours go by, and customers begin to complain. The server is no longer responding.

Joe opens up a VM, and Node.js is no longer running. No biggie: run node app.js again and the app is up and running again.

A few more hours go by and the same issue occurs again. It was all running well in localhost, but the high traffic is causing the server to behave unexpectedly in production. What can Joe do?

Enter PM2: the process manager for Node.js

Process managers enhance Node.js applications by allowing:

  • Monitoring the running services locally and in production
  • Running system administration tasks like starting and stopping applications without downtime
  • Logging metrics
  • Load balancing

Getting Started with PM2

To get started, create a simple server using Express.js.

npm init -y
npm install express

With basic packages set up, create an app.js file and paste the following code:

const app = require("express")();

app.get("/", (req, res) => {
  res.send("hello world");
});

app.listen(3000, () => {
  console.log("Server started on port 3000!");
});

PM2 is an NPM package installed globally on the system:

npm install -g pm2
pm2 start app.js
PM2 status

Notice that we do not get the log printed as would normally happen when running node app.js. Moreover, PM2 kicks us out of the long-running loop. If you go to localhost:3000, you can verify that the server is up.

Hello world on port 3000

The server is up and running in the back.

Process Management

PM2 lets you manually start, list, and stop active processes.

You can list out the running PM2 servers:

pm2 list
PM2 status 2

You can stop a single server:

pm2 stop app.js
pm2 stop 0
pm2 stop all

You can delete a saved server configuration:

pm2 delete app
pm2 delete 0
pm2 delete all

Just like with Nodemon, you can reload the server on changes:

pm2 start app.js --watch

Self-Recovery

Instead of running the Node.js application via node app.js, use pm2 start app.js. By running the app like this, PM2 will automatically recover the app from crashes. It automatically restarts the server if it fails.

Scaling and Load Balancing

By default, even if you are running the app on a multi-core CPU, Node.js runs an application on a single CPU core. If you have high traffic, all requests go to the single CPU instance while the rest are doing nothing.

The idea behind load balancing is to distribute the traffic across multiple cores:

  • pm2 start app.js -i 2
  • pm2 start app.js -i 4
  • pm2 start app.js -i 8
  • pm2 start app.js -i max
PM2 cores illustration

Node.js uses a specific pattern for load balancing, where all requests go to one core, and if it gets occupied, the requests are distributed to other cores. The result is an app that can handle large traffic.

Monitoring and Logging

Running pm2 monit app.js lets you monitor the stats of your application, including CPU and memory usage, and display logs in real time.

PM2 monitor app

Additionally, you can display logs per process or application:

  • pm2 logs processname
  • pm2 logs app-name

PM2 Main App

PM2 lets you monitor metrics on their main website.

PM2 homepage

Start by registering the app using the official PM2 guide. Once linked with the official PM2 Keymetrics site, you should see your app metrics displayed.

PM2 metrics

Final Words

PM2 is a powerful process manager that helps you orchestrate your applications using a few commands while you focus on building the product.

More readingView all
Next step

Apply these insights to your product

Our studio helps high-stakes teams turn engineering clarity into modular product delivery.

Valens.dev

The advanced software company for high-stakes products, AI workflows, and operational systems.

Recognition

Polet Award 2023 by the Foreign Trade Chamber of B&H for best exporter in the small companies category, services sector.

Read the article

Contact

Headquarters

Gradačačka 114, 71 000 Sarajevo

Branch Office

Braće Fejića 16, 88 000 Mostar

USA Operations

1023 E Lincolnway, Cheyenne, WY 82001, USA

Saudi Arabia Operations

3788 Al-Qasim Bin Ubaidullah Street, 6965, Jeddah 23416, Saudi Arabia

We are open

Mon-Fri: 9 am-6 pm

© 2026 All rights reserved
SARAJEVOMOSTARUSA / WYOMINGSAUDI ARABIA / JEDDAH