matimh.eu

PM2 Ecosystem Generator

api

bot

ecosystem.config.js

module.exports = {
  apps: [
    {
      name: "api",
      script: "dist/index.js",
      instances: "max",
      exec_mode: "cluster",
      watch: false,
      max_memory_restart: "500M",
      env: {
        "NODE_ENV": "production",
      },
    },
    {
      name: "bot",
      script: "bot/index.js",
      instances: 1,
      exec_mode: "fork",
      watch: false,
      max_memory_restart: "300M",
      env: {
        "NODE_ENV": "production",
      },
    },
  ],
};

run

pm2 start ecosystem.config.js
pm2 save
pm2 startup   # then run the command it prints
pm2 logs

cluster mode only works for Node apps that do not keep state in memory (or share it through Redis)