Monitoring with PM2 & Logs

Node js 8 min min read Updated: Mar 30, 2026 Advanced
Monitoring with PM2 & Logs
Advanced Topic 8 of 8

Monitoring with PM2 & Logs in Node.js

Deploying a Node.js application to production is only the first step. Once the application is live, you must continuously monitor its health, performance, and errors to keep it stable and reliable. This is where PM2 monitoring and logs become very useful.

PM2 is not only a process manager for running Node.js applications in production, but it also provides basic monitoring and logging features. These features help you track CPU usage, memory consumption, process restarts, crashes, and application logs in real time.

Key Concept: PM2 monitoring and logs help you observe application health, detect failures, and troubleshoot production issues in Node.js applications.

Why Monitoring is Important

In development, errors are easy to spot because you are running the application directly and watching the console. In production, things are different. Your application may run on a remote server for long periods, and problems like crashes, memory leaks, or slow performance may happen unexpectedly.

Monitoring helps you answer questions like:

  • Is the application running?
  • Has it crashed or restarted?
  • How much CPU is it using?
  • How much memory is it consuming?
  • Are any errors appearing in the logs?

What PM2 Provides for Monitoring

PM2 includes several useful monitoring features:

  • Process status tracking
  • CPU and memory usage monitoring
  • Application restart count
  • Live log viewing
  • Real-time terminal dashboard

These features make PM2 a good starting point for managing production Node.js apps.

Viewing Running Processes

The first command to know is:

bash pm2 list

This shows a table of all PM2-managed applications. It usually includes:

  • Application name
  • Process ID
  • Status (online, stopped, errored)
  • CPU usage
  • Memory usage
  • Restart count

This is often the first place to check if something goes wrong in production.

Understanding PM2 Process Status

Common statuses you may see include:

  • online: Application is running properly
  • stopped: Application has been stopped manually
  • errored: Application failed too many times or could not start
  • launching: Application is starting up

Watching these states helps you quickly understand whether your application is healthy.

Viewing Logs with PM2

Logs are one of the most useful tools for debugging and monitoring. PM2 automatically collects both standard output and error output from your Node.js app.

bash pm2 logs

This command streams live logs for all running PM2 applications.

To view logs for one specific application:

bash pm2 logs my-node-app

What You Can See in PM2 Logs

PM2 logs typically show:

  • Console output from your application
  • Error messages and stack traces
  • Startup messages
  • Unhandled exceptions
  • Runtime warnings

If your application crashes or behaves unexpectedly, logs are usually the first place to investigate.

Example of Application Logging

Suppose your app contains:

javascript console.log("Server started successfully"); console.error("Database connection failed");

PM2 will capture both outputs and store them in log files.

Viewing PM2 Logs in Real Time

PM2 logs stream live updates, which is useful while debugging a problem on a running server.

For example, when a request hits the server and your app logs request details, you can watch those logs immediately using:

bash pm2 logs

PM2 Monit Dashboard

PM2 also provides a built-in terminal dashboard for live monitoring:

bash pm2 monit

This dashboard displays:

  • Live CPU usage
  • Live memory usage
  • Running application processes
  • Log output in real time

It is especially useful when you want to quickly inspect application behavior without opening multiple tools.

Why CPU and Memory Monitoring Matters

CPU and memory usage are two of the most important signals in production monitoring.

  • High CPU usage may indicate heavy computation, infinite loops, or traffic spikes
  • High memory usage may indicate memory leaks or unusually large workloads

Watching these values over time helps you identify performance problems early.

Checking Detailed Process Information

PM2 can also show detailed information about a specific process:

bash pm2 show my-node-app

This gives more detailed information such as:

  • Script path
  • Execution mode
  • Environment variables
  • Restart count
  • Log file paths
  • Resource usage

Log Files Stored by PM2

PM2 stores logs on disk as well, not only in live terminal output. Usually, it creates:

  • Out log: Standard application logs
  • Error log: Error-related logs

These logs are often stored in the PM2 logs directory, which helps when you want to inspect older logs.

Flushing Logs

Over time, logs can grow large. PM2 allows you to clear current logs:

bash pm2 flush

This removes all current PM2 logs and can be useful during debugging or maintenance.

Restart Monitoring

PM2 also tracks how many times a process has restarted. Frequent restarts are a warning sign that the application may be crashing, running out of memory, or failing during startup.

You can see restart counts in:

bash pm2 list

Using Logs to Debug Production Issues

Suppose your app is returning 500 errors in production. PM2 logs can help you find:

  • Database connection failures
  • Missing environment variables
  • Unhandled exceptions
  • Invalid configuration values
  • Code errors after deployment

This is why structured logging inside your application is also important.

Combining PM2 with Winston or Other Loggers

PM2 captures console output, but production applications often use logging libraries like Winston or Pino for more structured logs.

In that case:

  • Your app generates structured logs
  • PM2 manages the process and captures those logs
  • You get better observability and easier debugging

PM2 Monitoring for Cluster Mode

If your application is running with multiple PM2 instances in cluster mode, PM2 monitoring helps you view resource usage across all processes.

bash pm2 start app.js -i max pm2 list

This is useful when scaling Node.js apps across CPU cores.

When PM2 Monitoring is Enough

PM2 monitoring is very useful for:

  • Small to medium production applications
  • Single-server deployments
  • Basic process health checks
  • Initial debugging and log inspection

For larger systems, PM2 is often combined with more advanced monitoring tools like Prometheus, Grafana, ELK stack, or cloud monitoring platforms.

Best Practices for PM2 Monitoring and Logs

  • Check pm2 list regularly after deployments
  • Use pm2 logs to debug live production issues
  • Monitor restart counts to detect unstable apps
  • Use pm2 monit for quick real-time inspection
  • Combine PM2 with structured logging libraries for better log quality
  • Rotate or manage log size to avoid disk space issues

Common Mistakes

  • Running apps with PM2 but never checking logs
  • Ignoring repeated restarts
  • Not monitoring memory growth over time
  • Relying only on console.log without structured logging
  • Letting log files grow indefinitely without cleanup

Real-World Use Cases

  • Debugging API crashes after deployment
  • Watching memory usage in long-running apps
  • Tracking logs for authentication failures
  • Monitoring clustered Node.js servers in production

Conclusion

Monitoring and log tracking are essential parts of running Node.js applications in production. PM2 makes this easier by providing process status, live logs, restart tracking, and a built-in monitoring dashboard.

For many production applications, PM2 is a practical first step toward better observability. When combined with proper application logging and external monitoring tools, it becomes even more powerful.

Quick Summary: PM2 monitoring and logs help you track process health, CPU and memory usage, restarts, and runtime logs, making Node.js production management more reliable.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators