PM2 Ecosystem Config Generator

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 생성기

PM2용 ecosystem.config.js를 즉시 생성 — 인스턴스 수, cluster/fork 모드, 환경변수, watch 모드, max_memory_restart 포함. Express, Next.js, NestJS 프리셋 제공.

Shown in pm2 list, pm2 logs and pm2 monit
Path relative to ecosystem.config.js
Only used in cluster mode
Restarts the app if it exceeds this memory usage
ecosystem.config.js
Fill the form (or pick a preset) and click "Generate ecosystem.config.js"

How to Use

STEP 1

Pick a preset or fill the form

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

Choose instances and mode

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 environment variables

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

Generate and deploy

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 savepm2 startup으로 재부팅 후에도 유지되게 하세요.

Frequently Asked Questions

Fork mode runs a single instance of your app as one Node.js process — simple and predictable, but it can only use one CPU core and has no built-in load balancing. Cluster mode spawns multiple instances behind PM2's internal load balancer, using the Node.js cluster module to share a single port across processes — ideal for HTTP APIs that need to use every CPU core. Fork mode suits background workers, cron jobs, or apps that already manage their own concurrency; cluster mode is the default choice for stateless web servers.
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.
A common starting point is 300-500M for small Node.js APIs and 500M-1G for apps with in-memory caching or larger dependency trees. Set it comfortably above your app's normal steady-state memory usage, which you can check with 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.
No — watch mode restarts your app whenever a file in the working directory changes, which is useful in local development but risky in production. Log files, uploaded content, or a deployment script writing new files can trigger unexpected restarts and drop in-flight requests. In production, keep watch: false and restart deliberately after each deploy — use pm2 reload ecosystem.config.js for zero-downtime restarts in cluster mode.

자주 묻는 질문

fork 모드는 앱을 하나의 Node.js 프로세스로 단일 실행합니다 — 단순하고 예측 가능하지만 CPU 코어 1개만 사용하고 내장 로드밸런싱이 없습니다. cluster 모드는 PM2의 내부 로드밸런서 뒤에서 여러 인스턴스를 실행하며 Node.js cluster 모듈로 하나의 포트를 여러 프로세스가 공유합니다 — 모든 CPU 코어를 활용해야 하는 HTTP API에 적합합니다. 백그라운드 워커나 크론 작업, 자체적으로 동시성을 관리하는 앱에는 fork 모드가 적합하고, 상태 없는 웹 서버에는 cluster 모드가 기본 선택입니다.
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만 실행하면 현재 세션에서는 유지되지만 재부팅에서는 살아남지 못합니다.
작은 Node.js API는 300-500M, 인메모리 캐싱이나 의존성이 많은 앱은 500M-1G 정도가 일반적인 시작점입니다. pm2 monit으로 확인한 앱의 평상시 메모리 사용량보다 충분히 높게 설정해, 일상적인 가비지 컬렉션 스파이크가 아니라 실제 메모리 누수일 때만 재시작되게 하세요. 메모리 사용량을 아직 파악 중이라면 값을 비워두는 것이 좋습니다 — 재시작 임계값을 너무 일찍 설정하면 누수를 드러내는 대신 가려버릴 수 있습니다.
아니요 — watch 모드는 작업 디렉터리의 파일이 변경될 때마다 앱을 재시작하는데, 로컬 개발에는 유용하지만 프로덕션에서는 위험합니다. 로그 파일, 업로드된 콘텐츠, 배포 스크립트가 새 파일을 쓰는 것만으로도 예기치 않은 재시작이 발생해 진행 중인 요청이 끊길 수 있습니다. 프로덕션에서는 watch: false를 유지하고 배포 후에는 의도적으로 재시작하세요 — cluster 모드에서 무중단 재시작을 하려면 pm2 reload ecosystem.config.js를 사용하세요.