Managing Node.js Process Lifecycles with PM2 | NodeFlux.eu Docs

Use PM2 process manager configuration files to handle auto-restarts, environment injection, and log management.

Steps

  1. Create ecosystem.config.cjs file in your Node.js project root.
  2. Define app configuration: module.exports = { apps: [{ name: "my-app", script: "./index.js", maxmemoryrestart: "450M" }] };
  3. Configure maxmemoryrestart to trigger soft reload if memory leaks push usage near plan RAM caps.
  4. Set autorestart: true and expbackoffrestart_delay: 100 to prevent tight crash loops.
  5. Set startup script to pm2-runtime start ecosystem.config.cjs in your service controls.
  6. Inspect application logs using the service panel output tab.

Notes