PM2 Ecosystem Generator
Build a copy-paste-ready PM2 ecosystem.config.js with cluster mode, env vars, and watch options.
Client-side only — nothing leaves your browser
No variables — block will be omitted from output.
module.exports = {
apps: [
{
name: 'my-app',
script: './server.js',
exec_mode: 'fork',
watch: false,
env: {
NODE_ENV: 'development',
},
env_production: {
NODE_ENV: 'production',
},
}
],
};
Save this as ecosystem.config.js in your project root, then run pm2 start ecosystem.config.js.
What is a PM2 Ecosystem File?
A PM2 ecosystem file (typically named ecosystem.config.js) is a single configuration file that defines one or more Node.js applications PM2 should manage. Instead of passing flags on the command line every time you start an app, you declare your app name, entry script, instance count, environment variables, log paths, and restart policies in one place. PM2 then loads them with pm2 start ecosystem.config.js, making your process configuration repeatable, version-controlled, and consistent across staging and production.
Common Ecosystem Fields
| Field | Purpose |
|---|---|
| name | Display name shown in pm2 list / pm2 monit |
| script | Path to your entry file (e.g. ./server.js or npm) |
| cwd | Working directory PM2 will cd into before running |
| instances | Number of processes (use 'max' for one per CPU) |
| exec_mode | fork (single process) or cluster (load-balanced) |
| watch | Restart on file changes — leave off in production |
| autorestart | Auto-restart on crash (default: true) |
| max_memory_restart | Restart if RAM exceeds limit (e.g. 500M, 1G) |
| out_file | Path for stdout log output |
| error_file | Path for stderr log output |
| env / env_production / env_staging | Environment variables loaded with --env <name> |
Useful PM2 Commands
| Command | What it does |
|---|---|
| pm2 start ecosystem.config.js | Start all apps defined in the file |
| pm2 start ecosystem.config.js --env production | Start using env_production variables |
| pm2 start ecosystem.config.js --only my-app | Start only one named app |
| pm2 reload ecosystem.config.js | Zero-downtime reload (cluster mode) |
| pm2 restart ecosystem.config.js | Restart all apps from the file |
| pm2 stop ecosystem.config.js | Stop all apps defined in the file |
| pm2 delete ecosystem.config.js | Remove all apps from PM2 |
| pm2 save | Persist current process list across reboots |
| pm2 startup | Generate and configure startup script for your OS |
Frequently Asked Questions
Where should I put my pm2 ecosystem.config.js file?
What is the difference between fork and cluster mode in PM2?
How do I start PM2 with the ecosystem file?
Why does PM2 say ecosystem.config.js not found?
Should I use .js, .cjs, or .mjs for my PM2 ecosystem file?
Related Tools
Need to manage SSH connections?
SSH Workbench lets you connect, browse files, and manage servers visually.
Try SSH Workbench Free