NodeJS Process Managers
A Node.js process manager is a tool that helps you control your application’s lifecycle, monitor running services, and perform system admin tasks to keep your project running smoothly.
The platform comes with three pre-configured process managers:
Select the desired one during environment creation or when redeploying a container.
Change the PROCESS_MANAGER Docker environment variable in existing containers to forever, npm, or pm2 (restart required to apply changes).
Process Manager (npm)
NPM not only manages packages but also starts your application. If you set the PROCESS_MANAGER variable to NPM on your NodeJS container, running “npm start” (or “npm run start”) will launch the script defined as “start” in your package.json.
For more details, see the official documentation.
PM2
PM2 offers many features for managing applications, including monitoring NodeJS processes. You can use various pm2 commands via SSH.
For example, after setting up your Node.js server, list running processes with:
pm2 list
This shows the default draw-game application running. You can remove this app with:
pm2 delete
And then deploy your project.
PM2 also lets you create configuration files listing all run options, useful for deploying microservices. You can find the configuration file reference, such as the default ecosystem.config.js file used to launch server.js for the “draw game” application.
Forever
Forever is a simple command-line tool that keeps your NodeJS processes running continuously. It ensures your project on the Node.js web server restarts automatically if it fails.
For main information on using forever, run:
forever --help
You can also specify application options in a JSON file. For example, for the default Draw game (after Node.js server installation), the /home/jelastic/ROOT/forever.json file looks like this:
{
"uid": "app1",
"append": true,
"watch": true,
"script": "server.js",
"sourceDir": "/home/jelastic/ROOT"
}
- uid: unique name for your app
- append: true to supplement logs, false to overwrite
- watch: true to enable automatic restart on code changes, false to avoid unexpected restarts after deployment from VCS
- script: name of the executable .js file
- sourceDir: absolute path to the script