Skip to content

PM2 Manager ​

PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

The PM2 Manager in FlashPanel provides an intuitive interface to manage your Node.js applications through PM2, making it easy to start, stop, restart, and monitor your processes.

Key Features ​

  • Process Management: Start, stop, restart, reload, and delete Node.js applications
  • Process Monitoring: View status, CPU usage, and memory consumption
  • Log Management: Access application logs for debugging and monitoring
  • Easy Deployment: Start new Node.js applications with simple form inputs
  • User Isolation: Run processes under specific system users for security

Prerequisites ​

Before using PM2 Manager, you need to:

  1. Be on a paid plan (PM2 Manager is available on paid plans only).
  2. Install Node.js on your server from the Applications page. PM2 is installed automatically along with Node.js.
  3. If the PM2 Manager page still asks you to install it, click Install to install the PM2 app.

Once installed, select PM2 in the server menu to open PM2 Manager. If it is not installed yet, PM2 appears in the Explore group of the menu.

Interface Overview ​

The PM2 Manager interface is organized around a main process list view with action buttons that open dialogs for specific operations:

  1. Process List: View and manage all PM2 processes
  2. Add New Process: Start a new Node.js application with PM2 (opens in dialog)
  3. View Logs: View logs for your PM2 processes (opens in dialog)

1. Process List ​

The PM2 Processes table shows all PM2 processes on your server.

Process List Columns ​

The process list shows detailed information for each process:

  • ID: The process ID (PID) assigned by the system
  • Name: The name of the process (custom or auto-generated)
  • Path: The path to the script file (hover to see command arguments)
  • Status: Current status (online, stopped, errored)
  • User: The system user under which the process is running
  • CPU: Current CPU usage percentage
  • Memory: Current memory usage

Process Actions ​

For each process, you can perform the following actions:

  • View Log: View logs for a process (opens in dialog)
  • Start: Start a stopped process (only shown when the process is not running)
  • Stop: Stop a running process (only shown when the process is running)
  • Restart: Restart a process (useful for applying code changes)
  • Reload: Reload a process (without downtime in cluster mode), only shown when the process is running
  • Delete: Remove a process from PM2

WARNING

The Delete button acts immediately without a confirmation dialog. Double-check before clicking it.

Refreshing Processes ​

Click the Refresh button at the top right to update the process list with the latest information from PM2.


2. Add New Process ​

This section allows you to start new Node.js applications using PM2 through a dialog interface.

Starting a Process ​

  1. Click the Add New button at the top of the process list
  2. In the Start New Process dialog, select the Website Isolation Username: the system user that runs the process (defaults to root)
  3. Enter the command: the arguments placed after pm2 start (e.g., app.js --name my-app or /path/to/your/script.js --max-memory-restart 512M)
  4. Click the Start button

After starting, the process list refreshes automatically to show your new process.


3. View Logs ​

This section allows you to view logs for your PM2 processes through a dialog interface, which is essential for debugging and monitoring.

Viewing Logs ​

  1. In the process list, click the View Log button of the process you want to examine
  2. In the dialog that opens, drag the Number of lines slider to choose how many log lines to retrieve (100-1000). The logs reload automatically when you change it
  3. The logs are displayed in a scrollable text area with syntax highlighting
  4. Click the Refresh button in the dialog to load the latest logs

Best Practices ​

  1. Use Process Names: Always give your processes meaningful names (the --name option) to identify them easily
  2. Monitor Resource Usage: Keep an eye on CPU and memory usage to ensure optimal performance
  3. Check Logs Regularly: Regularly review logs to catch errors and performance issues early
  4. Use User Isolation: Run processes under dedicated system users instead of root for improved security
  5. Use Cluster Mode: For production applications, consider PM2's cluster mode (the -i max option) to use multiple CPU cores

Troubleshooting ​

Process Won't Start ​

  • Check that the script path is correct and the file exists
  • Verify that the Node.js application doesn't have syntax errors
  • Check the logs for detailed error messages
  • Ensure the selected user has proper permissions to access the script

High Resource Usage ​

  • Review your application code for potential memory leaks
  • Consider implementing proper error handling to prevent crashes
  • Monitor logs for recurring errors that might cause resource spikes

Process Keeps Restarting ​

  • Check the application logs for unhandled exceptions
  • Ensure all required dependencies are installed
  • Verify that the application is not encountering runtime errors

For more detailed information about PM2 features and configuration options, refer to the official PM2 documentation.