PM2 — commandes de services
/pm2Analyser un projet et générer des commandes de service PM2 pour les services front-end, back-end ou de base de données détectés.
description: Analyze a project and generate PM2 service commands for detected frontend, backend, or database services.
PM2 Init
Auto-analyze project and generate PM2 service commands.
Command: $ARGUMENTS
Workflow
- Check PM2 (install via
npm install -g pm2if missing) - Scan project to identify services (frontend/backend/database)
- Generate config files and individual command files
Service Detection
| Type | Detection | Default Port |
|---|---|---|
| Vite | vite.config.* | 5173 |
| Next.js | next.config.* | 3000 |
| Nuxt | nuxt.config.* | 3000 |
| CRA | react-scripts in package.json | 3000 |
| Express/Node | server/backend/api directory + package.json | 3000 |
| FastAPI/Flask | requirements.txt / pyproject.toml | 8000 |
| Go | go.mod / main.go | 8080 |
Port Detection Priority: User specified > .env > config file > scripts args > default port
Generated Files
project/
├── ecosystem.config.cjs # PM2 config
├── {backend}/start.cjs # Python wrapper (if applicable)
└── .claude/
├── commands/
│ ├── pm2-all.md # Start all + monit
│ ├── pm2-all-stop.md # Stop all
│ ├── pm2-all-restart.md # Restart all
│ ├── pm2-{port}.md # Start single + logs
│ ├── pm2-{port}-stop.md # Stop single
│ ├── pm2-{port}-restart.md # Restart single
│ ├── pm2-logs.md # View all logs
│ └── pm2-status.md # View status
└── scripts/
├── pm2-logs-{port}.ps1 # Single service logs
└── pm2-monit.ps1 # PM2 monitorWindows Configuration (IMPORTANT)
ecosystem.config.cjs
**Must use .cjs extension**
module.exports = {
apps: [
// Node.js (Vite/Next/Nuxt)
{
name: 'project-3000',
cwd: './packages/web',
script: 'node_modules/vite/bin/vite.js',
args: '--port 3000',
interpreter: 'C:/Program Files/nodejs/node.exe',
env: { NODE_ENV: 'development' }
},
// Python
{
name: 'project-8000',
cwd: './backend',
script: 'start.cjs',
interpreter: 'C:/Program Files/nodejs/node.exe',
env: { PYTHONUNBUFFERED: '1' }
}
]
}Framework script paths:
| Framework | script | args |
|---|---|---|
| Vite | node_modules/vite/bin/vite.js | --port {port} |
| Next.js | node_modules/next/dist/bin/next | dev -p {port} |
| Nuxt | node_modules/nuxt/bin/nuxt.mjs | dev --port {port} |
| Express | src/index.js or server.js | - |
Python Wrapper Script (start.cjs)
const { spawn } = require('child_process');
const proc = spawn('python', ['-m', 'uvicorn', 'app.main:app', '--host', '0.0.0.0', '--port', '8000', '--reload'], {
cwd: __dirname, stdio: 'inherit', windowsHide: true
});
proc.on('close', (code) => process.exit(code));Command File Templates (Minimal Content)
pm2-all.md (Start all + monit)
Start all services and open PM2 monitor.cd "{PROJECTROOT}" && pm2 start ecosystem.config.cjs && start wt.exe -d "{PROJECTROOT}" pwsh -NoExit -c "pm2 monit"
pm2-all-stop.md
Stop all services.cd "{PROJECT_ROOT}" && pm2 stop all
pm2-all-restart.md
Restart all services.cd "{PROJECT_ROOT}" && pm2 restart all
pm2-{port}.md (Start single + logs)
Start {name} ({port}) and open logs.cd "{PROJECTROOT}" && pm2 start ecosystem.config.cjs --only {name} && start wt.exe -d "{PROJECTROOT}" pwsh -NoExit -c "pm2 logs {name}"
pm2-{port}-stop.md
Stop {name} ({port}).cd "{PROJECT_ROOT}" && pm2 stop {name}
pm2-{port}-restart.md
Restart {name} ({port}).cd "{PROJECT_ROOT}" && pm2 restart {name}
pm2-logs.md
View all PM2 logs.cd "{PROJECT_ROOT}" && pm2 logs
pm2-status.md
View PM2 status.cd "{PROJECT_ROOT}" && pm2 status
PowerShell Scripts (pm2-logs-{port}.ps1)
Set-Location "{PROJECT_ROOT}"
pm2 logs {name}PowerShell Scripts (pm2-monit.ps1)
Set-Location "{PROJECT_ROOT}"
pm2 monitKey Rules
- Config file:
ecosystem.config.cjs(not .js) - Node.js: Specify bin path directly + interpreter
- Python: Node.js wrapper script +
windowsHide: true - Open new window:
start wt.exe -d "{path}" pwsh -NoExit -c "command" - Minimal content: Each command file has only 1-2 lines description + bash block
- Direct execution: No AI parsing needed, just run the bash command
Execute
Based on $ARGUMENTS, execute init:
- Scan project for services
- Generate
ecosystem.config.cjs - Generate
{backend}/start.cjsfor Python services (if applicable) - Generate command files in `.claude/