← 返回
开发者工具 中文

PM2 Process Manager

Manage Node.js applications with PM2 process manager. Use for deploying, monitoring, and auto-restarting Node apps in production. Covers starting apps, viewing logs, setting up auto-start on boot, and managing multiple processes.
使用PM2进程管理器管理Node.js应用程序。用于在生产环境中部署、监控和自动重启Node.js应用,包括启动应用、查看日志、设置开机自启及管理多进程。
asteinberger
开发者工具 clawhub v1.0.0 1 版本 99796 Key: 无需
★ 3
Stars
📥 3,365
下载
💾 208
安装
1
版本
#latest

概述

PM2 Process Manager

Production process manager for Node.js with built-in load balancer.

Install

npm install -g pm2

Quick Start

# Start an app
pm2 start app.js
pm2 start npm --name "my-app" -- start
pm2 start "npm run start" --name my-app

# With specific port/env
pm2 start npm --name "my-app" -- start -- --port 3000
PORT=3000 pm2 start npm --name "my-app" -- start

Common Commands

# List processes
pm2 list
pm2 ls

# Logs
pm2 logs              # All logs
pm2 logs my-app       # Specific app
pm2 logs --lines 100  # Last 100 lines

# Control
pm2 restart my-app
pm2 stop my-app
pm2 delete my-app
pm2 reload my-app     # Zero-downtime reload

# Info
pm2 show my-app
pm2 monit             # Real-time monitor

Auto-Start on Boot

# Save current process list
pm2 save

# Generate startup script (run the output command with sudo)
pm2 startup

# Example output - run this:
# sudo env PATH=$PATH:/opt/homebrew/bin pm2 startup launchd -u username --hp /Users/username

Next.js / Production Builds

# Build first
npm run build

# Start production server
pm2 start npm --name "my-app" -- start

# Or with ecosystem file
pm2 start ecosystem.config.js

Ecosystem File (ecosystem.config.js)

module.exports = {
  apps: [{
    name: 'my-app',
    script: 'npm',
    args: 'start',
    cwd: '/path/to/app',
    env: {
      NODE_ENV: 'production',
      PORT: 3000
    }
  }]
}

Useful Flags

FlagDescription
-------------------
--nameProcess name
--watchRestart on file changes
-i maxCluster mode (all CPUs)
--max-memory-restart 200MAuto-restart on memory limit
--cron "0 "Scheduled restart

Cleanup

pm2 delete all        # Remove all processes
pm2 kill              # Kill PM2 daemon
pm2 unstartup         # Remove startup script

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-28 11:02 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,801
developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 68 📥 180,188
data-analysis

Home Music

asteinberger
控制全屋音乐场景,结合Spotify播放与Airfoil音箱路由,支持早安、派对、放松模式快速切换。
★ 1 📥 2,780