Build a complete ecosystem.config.js for PM2 — instances, cluster/fork mode, environment variables, watch mode, and max_memory_restart. Presets for Express, Next.js, and NestJS.
PM2용 ecosystem.config.js를 즉시 생성 — 인스턴스 수, cluster/fork 모드, 환경변수, watch 모드, max_memory_restart 포함. Express, Next.js, NestJS 프리셋 제공.
Presets
App
Environment Variables
Advanced
How to Use
STEP 1
Click a preset (Express API, Next.js, NestJS) to auto-fill sensible defaults, then adjust the app name and script path to match your project.
STEP 2
Pick cluster mode with "max" instances to use every CPU core for a stateless API, or fork mode with 1 instance for background workers.
STEP 3
Add KEY=value pairs like NODE_ENV=production or PORT=3000, set a max_memory_restart safety net, and keep watch mode off in production.
STEP 4
Copy or download the file, run pm2 start ecosystem.config.js, then pm2 save and pm2 startup so it survives a reboot.
사용 방법
STEP 1
프리셋(Express API, Next.js, NestJS)을 클릭하면 기본값이 자동 입력됩니다. 앱 이름과 script 경로를 프로젝트에 맞게 수정하세요.
STEP 2
상태 없는 API는 cluster 모드 + "max" 인스턴스로 모든 CPU 코어를 활용하고, 백그라운드 워커는 fork 모드 + 인스턴스 1개를 사용하세요.
STEP 3
NODE_ENV=production, PORT=3000 같은 KEY=value 쌍을 추가하고, max_memory_restart 안전장치를 설정하며, 프로덕션에서는 watch 모드를 꺼두세요.
STEP 4
파일을 복사·다운로드한 뒤 pm2 start ecosystem.config.js를 실행하고, pm2 save와 pm2 startup으로 재부팅 후에도 유지되게 하세요.
Frequently Asked Questions
instances: "max" tells PM2 to detect the number of CPU cores on the host and spawn that many cluster instances automatically, so the same ecosystem.config.js scales correctly whether you deploy to a 2-core or 16-core VPS. You can also use instances: -1 to use all cores minus one, leaving headroom for other services, or a fixed number like 2 for predictable memory usage. "max" only applies in cluster mode — fork mode always runs a single instance.pm2 save writes the current process list to PM2's dump file so it can be restored later. pm2 startup generates and configures a system init script (systemd, upstart, etc.) that resurrects your saved process list on server reboot. Without both steps, PM2 forgets your apps after a restart or a crash-and-reboot cycle — running only pm2 start ecosystem.config.js keeps the app alive for the current session but does not survive a reboot.pm2 monit, so it only triggers on real leaks rather than everyday garbage-collection spikes. Leave it unset while you are still profiling memory usage — adding a restart threshold too early can mask a leak instead of surfacing it.watch: false and restart deliberately after each deploy — use pm2 reload ecosystem.config.js for zero-downtime restarts in cluster mode.자주 묻는 질문
instances: "max"는 PM2가 호스트의 CPU 코어 수를 감지해 그만큼 cluster 인스턴스를 자동으로 생성하게 합니다 — 같은 ecosystem.config.js로 2코어 VPS와 16코어 VPS 모두에 맞게 확장됩니다. 다른 서비스를 위한 여유를 남기려면 instances: -1(전체 코어 수-1)을 쓰거나, 메모리 사용량을 예측 가능하게 하려면 2 같은 고정 숫자를 쓸 수 있습니다. "max"는 cluster 모드에서만 적용되며 fork 모드는 항상 인스턴스 1개로 실행됩니다.pm2 save는 현재 프로세스 목록을 PM2의 덤프 파일에 저장해 나중에 복원할 수 있게 합니다. pm2 startup은 서버 재부팅 시 저장된 프로세스 목록을 되살리는 시스템 초기화 스크립트(systemd, upstart 등)를 생성·등록합니다. 두 단계를 모두 하지 않으면 재시작이나 재부팅 후 PM2가 앱을 기억하지 못합니다 — pm2 start ecosystem.config.js만 실행하면 현재 세션에서는 유지되지만 재부팅에서는 살아남지 못합니다.pm2 monit으로 확인한 앱의 평상시 메모리 사용량보다 충분히 높게 설정해, 일상적인 가비지 컬렉션 스파이크가 아니라 실제 메모리 누수일 때만 재시작되게 하세요. 메모리 사용량을 아직 파악 중이라면 값을 비워두는 것이 좋습니다 — 재시작 임계값을 너무 일찍 설정하면 누수를 드러내는 대신 가려버릴 수 있습니다.watch: false를 유지하고 배포 후에는 의도적으로 재시작하세요 — cluster 모드에서 무중단 재시작을 하려면 pm2 reload ecosystem.config.js를 사용하세요.