Process Managers

Node.js Process Managers

A Node.js process manager controls the application lifecycle, monitors running services, and simplifies common administration tasks that help keep a project operational. The platform provides npm, PM2, and Forever as preconfigured options.

Node.js process managers
The platform provides npm, PM2, and Forever process managers.

Select a Process Manager

You can choose the process manager during environment creation, while redeploying a Node.js container, or by updating the container variable in an existing environment.

Method 1: Select a Tag

Choose the appropriate process-manager tag during environment creation or container redeployment.

Select a Node.js process manager in the wizard
Select npm, PM2, or Forever through the Node.js container tag.

Method 2: Set the Environment Variable

In an existing Node.js container, edit the PROCESS_MANAGER Docker environment variable and assign one of these values:

  • npm
  • pm2
  • forever
Set the Node.js process manager variable
Set PROCESS_MANAGER to npm, pm2, or forever.
!

Restart required

Restart the Node.js container after changing the PROCESS_MANAGER variable so the new process manager is applied.

Process Manager (npm)

In addition to package management, npm can start a Node.js application. When npm is selected as the PROCESS_MANAGER value, the platform runs:

npm start

This is an alias for:

npm run start

The command launches the script defined in the start section of the project’s package.json file.

Best suited forProjects that already define a complete start command in package.json.
Startup sourceThe scripts.start value in package.json.
Management levelA straightforward application-start method without the broader monitoring features of PM2.

PM2

PM2 provides a broad set of application-management capabilities, including monitoring of running Node.js processes. PM2 commands can be executed directly through SSH.

List Running Processes

pm2 list
List running Node.js processes with PM2
The PM2 list command displays the running Node.js applications.

After creating a Node.js server, the command displays the default Draw Game application as a running process.

Delete a Process

Remove an existing PM2-managed application before deploying another project:

pm2 delete {process_name_or_id}
Delete a Node.js process with PM2
Delete the default process before deploying and starting another application.

PM2 Configuration Files

PM2 supports configuration files that define application startup options. This is useful for microservice-based deployments because several applications can be described in one file.

The default ecosystem.config.js file can be used to launch server.js as the Draw Game application.

PM2 is suitable for complex deployments

Use a PM2 ecosystem file when the project includes several services, requires process monitoring, or needs multiple startup options to be managed together.

Forever

Forever is a simple command-line tool that keeps Node.js processes running continuously. It maintains a child process and automatically restarts it after a failure.

View Forever Help

forever --help
Forever process manager help
Review the Forever commands, options, and usage information.

Configure the Application through JSON

Forever can read application options from a JSON configuration file. The default Draw Game example uses /home/jelastic/ROOT/forever.json:

{
  "uid": "app1",
  "append": true,
  "watch": true,
  "script": "server.js",
  "sourceDir": "/home/jelastic/ROOT"
}
uidSets a unique name for the application.
appendWhen true, new log output is appended. When false, the log is overwritten.
watchEnables or disables automatic child-process restart after application-code changes.
scriptDefines the executable JavaScript file.
sourceDirProvides the absolute directory path containing the specified script.
i

VCS deployment consideration

Set watch to false to avoid an unexpected process restart after deployment from a version-control repository, including automatic deployment.

Expected Result

The Node.js container uses the selected npm, PM2, or Forever process manager. The application is started according to the selected manager’s configuration and can be monitored or restarted using the corresponding commands and settings.

Important Notes

  • Select the process manager during environment creation, container redeployment, or through PROCESS_MANAGER.
  • Restart the container after changing the process-manager variable.
  • npm requires a valid start script in package.json.
  • PM2 provides broader monitoring and multi-application configuration features.
  • Forever is suitable for straightforward continuous process execution and automatic restart.
  • Disable Forever file watching when VCS deployment should not trigger an unexpected restart.

Common Issues and Solutions

npm application does not startConfirm that package.json contains a valid scripts.start command.
New process manager is not appliedCheck the PROCESS_MANAGER value and restart the Node.js container.
PM2 still runs the default applicationUse pm2 list to identify it and pm2 delete to remove it before starting the new project.
Forever restarts after deploymentSet watch to false in forever.json.
Script file cannot be foundReview the script and sourceDir values in the process-manager configuration.