DEV Community

Cover image for PM2 Cheatsheet
Hash
Hash

Posted on

PM2 Cheatsheet

Hello friends,
I've created another cheatsheet, it's for pm2, which is actually my personal notes like the other articles. It could be helpful for you too.

What's PM2

PM2, or Process Manager 2, is a versatile and powerful process manager for Node.js applications. It's designed to simplify the deployment, management, and monitoring of Node.js applications in production environments.

PM2 comes with a range of features:

Process Management
Monitoring
Logging
Cluster Mode
Startup Script Generation
Environment and Configuration
Version Management
Security
Update Management
Global CLI

I personally utilize it primarily for managing processes and logging, allowing you to start, stop, and automatically restart Node.js processes.

Here's a list of commonly used PM2 commands along with examples:

  • Start a Node.js application with PM2:
pm2 start app.js
Enter fullscreen mode Exit fullscreen mode
  • Start a NextJs application with a specific name:
pm2 start npm --name app-name -- start
Enter fullscreen mode Exit fullscreen mode
  • List all PM2 processes:
pm2 ls
Enter fullscreen mode Exit fullscreen mode
  • Show detailed information about a specific process:
pm2 show your-app-name
Enter fullscreen mode Exit fullscreen mode
  • View real-time logs of a specific process:
pm2 logs your-app-name
Enter fullscreen mode Exit fullscreen mode
  • Monitor system resources for all PM2 processes:
pm2 monit
Enter fullscreen mode Exit fullscreen mode

-Stop a PM2 process:

pm2 stop your-app-name
Enter fullscreen mode Exit fullscreen mode
  • Restart a PM2 process:
pm2 restart your-app-name
Enter fullscreen mode Exit fullscreen mode
  • Delete a PM2 process:
pm2 delete your-app-name
Enter fullscreen mode Exit fullscreen mode
  • Reload a PM2 process (restarting without downtime):
pm2 reload your-app-name
Enter fullscreen mode Exit fullscreen mode
  • Save the list of PM2 processes for automatic startup:
pm2 save
Enter fullscreen mode Exit fullscreen mode
  • Startup PM2 on system boot:
pm2 startup
Enter fullscreen mode Exit fullscreen mode
  • View detailed status of all PM2 processes:
pm2 status
Enter fullscreen mode Exit fullscreen mode
  • Clear logs for a specific process:
pm2 flush your-app-name
Enter fullscreen mode Exit fullscreen mode

These commands should cover most of the common tasks you need to perform when working with PM2. For more detailed information, you can always refer to the official PM2 documentation.

Also if you're looking to deploy NextJS Website From Scratch (with Ubuntu, NGINX and pm2) these videos would be helpful:

refs

Top comments (0)