Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nestjs-mod/pm2

nestjs-mod230MIT1.14.1TypeScript support: included

Production process manager for Node.JS applications with a built-in load balancer for NestJS-mod (Generator ecosystem.config.json for https://www.npmjs.com/package/pm2)

nestjs, nestjs-mod, modules, mod, pm2, infrastructure

readme

@nestjs-mod/pm2

Production process manager for Node.JS applications with a built-in load balancer for NestJS-mod (Generator ecosystem.config.json for https://www.npmjs.com/package/pm2)

NPM version monthly downloads Telegram Discord

Installation

npm i --save pm2 dotenv @nestjs-mod/pm2

Modules

Link Category Description
Pm2 infrastructure Production process manager for Node.JS applications with a built-in load balancer for NestJS-mod (Generator ecosystem.config.json for https://www.npmjs.com/package/pm2)

Modules descriptions

Pm2

Production process manager for Node.JS applications with a built-in load balancer for NestJS-mod (Generator ecosystem.config.json for https://www.npmjs.com/package/pm2)

Use in NestJS-mod

An example you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-terminus.

import { PACKAGE_JSON_FILE, ProjectUtils, bootstrapNestApplication } from '@nestjs-mod/common';
import { ECOSYSTEM_CONFIG_FILE, Pm2 } from '@nestjs-mod/pm2';
import { join } from 'path';

const rootFolder = join(__dirname, '..', '..', '..');
const appFolder = join(rootFolder, 'apps', 'example-terminus');

bootstrapNestApplication({
  globalEnvironmentsOptions: { debug: true },
  globalConfigurationOptions: { debug: true },
  modules: {
    system: [
      ProjectUtils.forRoot({
        staticConfiguration: {
          applicationPackageJsonFile: join(appFolder, PACKAGE_JSON_FILE),
          packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE),
          envFile: join(rootFolder, '.env'),
        },
      }),
    ],
    infrastructure: [
      Pm2.forRoot({
        configuration: {
          ecosystemConfigFile: join(rootFolder, ECOSYSTEM_CONFIG_FILE),
          applicationScriptFile: join('dist/apps/example-terminus/main.js'),
        },
      }),
    ],
  },
});

After connecting the module to the application and npm run build and starting generation of documentation through npm run docs:infrastructure, you will have new files and scripts to run.

New scripts mostly package.json

{
  "scripts": {
    "_____pm2 prod infra_____": "_____pm2 prod infra_____",
    "pm2:start": "./node_modules/.bin/pm2 start ./ecosystem.config.json",
    "pm2:stop": "./node_modules/.bin/pm2 delete all"
  },
  "scriptsComments": {
    "pm2:start": ["Launch all applications in PM2 mode"],
    "pm2:stop": ["Stop all applications in PM2 mode"]
  }
}

Config file for start all built applications ecosystem.config.json

{
  "apps": [
    { "name": "terminus", "script": "node ./dist/apps/example-terminus/main.js", "node_args": "-r dotenv/config" }
  ]
}

Configuration

Key Description Constraints Default Value
ecosystemConfigFile Configuration file for PM2 isNotEmpty (ecosystemConfigFile should not be empty) - -
applicationScriptFile Application script file name for run isNotEmpty (applicationScriptFile should not be empty) - -
autorestart Enable or disable auto restart after process failure optional - -
name An arbitrary name that can be used to interact with (e.g. restart) the process later in other commands. Defaults to the script name without its extension (eg “testScript” for “testScript.js”) optional - -
script The path of the script to run optional - -
args A string or array of strings composed of arguments to pass to the script optional - -
interpreter_args A string or array of strings composed of arguments to call the interpreter process with. Eg “–harmony” or [”–harmony”,”–debug”]. Only applies if interpreter is something other than “none” optional - -
cwd The working directory to start the process with optional - -
output The path to a file to append stdout output to. Can be the same file as error optional - -
error The path to a file to append stderr output to. Can be the same file as output optional - -
log_date_format The display format for log timestamps (eg “YYYY-MM-DD HH:mm Z”). The format is a moment display format optional - -
pid The path to a file to write the pid of the started process. The file will be overwritten. Note that the file is not used in any way by pm2 and so the user is free to manipulate or remove that file at any time. The file will be deleted when the process is stopped or the daemon killed optional - -
min_uptime The minimum uptime of the script before it’s considered successfully started optional - -
max_restarts The maximum number of times in a row a script will be restarted if it exits in less than min_uptime optional - -
max_memory_restart If sets and script’s memory usage goes about the configured number, pm2 restarts the script. Uses human-friendly suffixes: ‘K’ for kilobytes, ‘M’ for megabytes, ‘G’ for gigabytes’, etc. Eg “150M” optional - -
node_args Arguments to pass to the interpreter optional -r dotenv/config -
time Prefix logs with time optional - -
wait_ready This will make PM2 listen for that event. In your application you will need to add process.send('ready'); when you want your application to be considered as ready. optional - -
kill_timeout The number of milliseconds to wait after a stop or restart command issues a SIGINT signal to kill the script forceably with a SIGKILL signal optional - -
restart_delay Number of millseconds to wait before restarting a script that has exited optional - -
interpreter The interpreter for your script (eg “python”, “ruby”, “bash”, etc). The value “none” will execute the ‘script’ as a binary executable optional - -
exec_mode If sets to ‘cluster’, will enable clustering (running multiple instances of the script) optional - -
instances How many instances of script to create. Only relevant in exec_mode ‘cluster’ optional - -
merge_logs If true, merges the log files for all instances of script into one stderr log and one stdout log. Only applies in ‘cluster’ mode. For example, if you have 4 instances of ‘test.js’ started via pm2, normally you would have 4 stdout log files and 4 stderr log files, but with this option set to true you would only have one stdout file and one stderr file optional - -
watch If set to true, the application will be restarted on change of the script file optional - -
force By default, pm2 will only start a script if that script isn’t already running (a script is a path to an application, not the name of an application already running). If force is set to true, pm2 will start a new instance of that script optional - -
ignore_watch - optional - -
cron - optional - -
execute_command - optional - -
write - optional - -
source_map_support - optional - -
disable_source_map_support - optional - -
env The environment variables to pass on to the process optional - -

Back to Top

License

MIT

changelog

1.14.0 (2025-05-24)

Features

  • add new feature module prisma-tools (1470204)

1.13.5 (2025-05-20)

Bug Fixes

  • update scripts for run server application (b47e4a7)

1.13.4 (2025-05-20)

Bug Fixes

  • update scripts for run server application (0603823)

1.13.3 (2025-02-20)

Bug Fixes

  • update pg-flyway version (91f058d)

1.13.2 (2025-01-24)

Bug Fixes

1.13.1 (2025-01-22)

Bug Fixes

  • lock version of case-anything (511d86b)

1.13.0 (2025-01-16)

Features

  • append new infrastructure module for work with pf-flyway (9a6ba03)

1.12.4 (2024-12-30)

Bug Fixes

1.12.3 (2024-09-22)

Bug Fixes

1.12.2 (2024-08-15)

Bug Fixes

1.12.1 (2024-08-15)

Bug Fixes

  • added merging of the original application options with new options (4d126b8)
  • update nestjs-mod libs (3481d3a)

1.12.0 (2024-07-29)

Features

  • npm run nx -- migrate latest && npm run npx nx migrate --run-migrations (e16fb8a)
  • npm run update:lib-versions && npm run manual:prepare (4c27038)
  • npm run update:nestjs-mod-versions (f9ebf6b)

1.11.1 (2024-05-04)

Bug Fixes

1.11.0 (2024-03-07)

Features

  • update logic for search env keys in docker compose services, use service name as prefix for env key name (e544c7b)

1.10.0 (2024-03-06)

Features

  • add @nestjs-mod/authorizer for work with https://authorizer.dev/, add DockerComposeAuthorizer for deploy authorizer server, add option notStaticKeysOfEnvironments in docker services for exclude some keys from generated dot env file (12380a4)

1.9.1 (2024-02-22)

Bug Fixes

  • add transform: new NumberTransformer() for all number options in settings (71fc6d8)

1.9.0 (2024-02-13)

Features

  • add DockerComposeMinio in @nestjs-mod/docker-compose, add @nestjs-mod/minio (0d3f9b7)
  • add DockerComposeNginx to @nestjs-mod/docker-compose, add use nginx in docker-compose for minio and disable cors validations, update readme in all modules (87cb34a)

1.8.0 (2024-02-09)

Features

  • add GraphqlModule in @nestjs-mod/graphql, add @nestjs-mod/cache-manager, update code in @nestjs-mod/pino, update readme in all modules, update @nestjs-mod/common version (c36b138)

1.7.0 (2024-02-07)

Bug Fixes

Features

  • add DockerComposeRedis in @nestjs-mod/docker-compose, add @nestjs-mod/cache-manager, rename FlywayModule to Flyway, rename NestjsPinoLogger to NestjsPinoLoggerModule, rename TerminusHealthCheck to TerminusHealthCheckModule, remove all async work with fs (1c5474a)

1.6.2 (2024-02-01)

Bug Fixes

  • add create directory when we try create or update some files from infrastructure logic (90e3ea8)

1.6.1 (2024-02-01)

Bug Fixes

1.6.0 (2024-02-01)

Bug Fixes

  • move dependencies from code to dependenciesInfo and readme, update generator for ecosystem.config.json (7aa6ce1)

Features

1.5.1 (2024-01-30)

Bug Fixes

  • update logic for generate package json scripts, add order for categories (66e0753)

1.5.0 (2024-01-30)

Features

  • the files and commands added to the infrastructure have been expanded, and examples of working with libraries have been added (7f6c852)

1.4.2 (2024-01-24)

Bug Fixes

1.4.1 (2024-01-24)

Bug Fixes

1.4.0 (2024-01-23)

Features

  • add @nestjs-mod/prisma, update docker-compose for correct work with envs (750f302)

1.3.0 (2024-01-21)

Features

  • add @nestjs-mod/docker-compose (b5ddd56)

1.2.0 (2024-01-19)

Features

1.1.2 (2024-01-18)

Bug Fixes

  • add peerDependenciesMeta (872378b)

1.1.1 (2024-01-18)

Bug Fixes

  • move part of deps to peerDependencies (5891862)

1.1.0 (2024-01-17)

Features

1.0.2 (2024-01-17)

Bug Fixes

1.0.1 (2024-01-16)

Bug Fixes

  • pm2: update scripts for pm2 start (5a54244)

1.0.0 (2024-01-16)

Bug Fixes

Features