Skip to content
____________________
V.1.0.0 // SECURE CONNECTION
Return_to_vault
[CONSTRUCT: 2026-02-08]

PM2 Ecosystem Deploy Config

DevOpsNode.jsVPS

PM2 Ecosystem Deploy Config

The actual PM2 config running thechosenvictor.com on a Hetzner VPS. Auto-restart on crash, memory limits, structured logging, and a graceful shutdown timeout so in-flight requests finish before the process dies. Plus the 4-line deploy script that replaced manual SSH sessions.

When to Use

  • Self-hosting a Node.js app on a VPS instead of a managed platform
  • You need process management with auto-restart, log rotation, and memory limits
  • Setting up a repeatable deploy pipeline that's simpler than CI/CD but more reliable than "ssh in and run commands"

The Code

// ecosystem.config.js - PM2 process config for Next.js
module.exports = {
  apps: [{
    name: 'thechosenvictor',
    script: 'node_modules/next/dist/bin/next',
    args: 'start',
    cwd: '/home/deploy/app',
    instances: 1,
    exec_mode: 'fork',
    env: {
      NODE_ENV: 'production',
      PORT: 3000,
    },
    // Auto-restart on crash
    autorestart: true,
    max_restarts: 10,
    restart_delay: 5000,
    // Memory limit (restart if exceeded)
    max_memory_restart: '512M',
    // Log management
    log_date_format: 'YYYY-MM-DD HH:mm:ss',
    error_file: '/home/deploy/logs/error.log',
    out_file: '/home/deploy/logs/out.log',
    merge_logs: true,
    // Graceful shutdown
    kill_timeout: 5000,
    listen_timeout: 10000,
  }],
};

// Deploy script (deploy.sh):
// cd ~/app && git pull origin main
// npm ci --production
// npx next build
// pm2 reload ecosystem.config.js --update-env

Notes

Use pm2 reload instead of pm2 restart for zero-downtime deploys. Reload does a graceful process replacement; restart kills and respawns. The 512M memory limit is generous for a Next.js portfolio site, but it prevents runaway memory leaks from silently eating your VPS.

Share

"End of transmission."

[CLOSE_CONSTRUCT]