zaro

What is the default path of PM2?

Published in PM2 Paths 2 mins read

The default path where PM2 stores its operational data, configuration, and logs is within the user's home directory, specifically in a hidden directory named .pm2.

Understanding the PM2 Default Directory

PM2, the production process manager for Node.js applications, centralizes its essential files within a specific default directory to manage your applications efficiently. This directory typically houses:

  • Logs: All application and PM2 internal logs are stored here. For instance, by default, logs are saved into $HOME/.pm2/logs.
  • Configuration Files: PM2's internal configuration, including process lists and environmental settings, resides in this location.
  • Process Files: Information about the running processes, PIDs, and other runtime data.

This design ensures that PM2 can operate effectively for individual users without requiring global system-wide permissions for data storage.

Breaking Down the Path: $HOME/.pm2

The default path is represented as $HOME/.pm2. Let's break down its components:

  • $HOME: This is an environment variable that points to the current user's home directory. Its exact location varies depending on the operating system:
    • Linux/macOS: Typically /home/yourusername or /Users/yourusername.
    • Windows: Usually C:\Users\yourusername.
  • .pm2: This is a hidden directory (prefixed with a dot on Unix-like systems) created by PM2 within the $HOME directory. This convention is common for applications storing user-specific configuration and data.

Practical Implications of the Default Path

Understanding PM2's default path is crucial for several reasons:

  • Log Access: To inspect application logs or PM2's internal logs, you would navigate to $HOME/.pm2/logs.
  • Troubleshooting: When an application misbehaves or PM2 itself encounters issues, examining files within this directory can provide valuable diagnostic information.
  • Backup and Migration: If you need to back up your PM2 configuration or migrate your applications to another server, knowing this central location simplifies the process.

While PM2 defaults to this path, advanced users or specific production environments might configure PM2 to use different log or data directories via environment variables or custom configuration files, though this requires explicit setup. For most standard installations, the $HOME/.pm2 directory serves as the primary operational hub.