Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

pm2

import pm2 from 'pm2'
import os from 'os'

pm2.connect((err: Error) => {
  if (!err) {
    pm2.start(
      {
        name: 'express-rest-api',
        script: 'dist/main.js',
        watch: false,
        env: { NODE_ENV: 'production', NODE_OPTIONS: '--max_old_space_size=32768' },
        exec_mode: 'cluster',
        instances: os.cpus().length,
        max_memory_restart: '512M',
        kill_timeout: 6000
      },
      (err: Error, _proc: pm2.Proc) => {
        if (err) {
          pm2.restart('express-rest-api', (err: Error, _proc: pm2.Proc) => {
            if (!err) return pm2.disconnect()
          })
        }
      }
    )
  }
})
Source by pm2.keymetrics.io #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
1+2 =