Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime, and to facilitate common system admin tasks.
Process Management
Start an application with PM2 and keep it running in the background.
pm2 start app.js
Load Balancing
Enable load balancing by starting multiple instances of the application across all CPUs.
pm2 start app.js -i max
Monitoring
Monitor all processes launched with PM2 using a terminal-based dashboard.
pm2 monit
Logging
Display logs of all processes in real-time, or target specific processes.
pm2 logs
Startup Script
Generate a startup script to resurrect PM2 and all processes on server reboot.
pm2 startup
Update Processes
Reload all processes in the cluster without downtime.
pm2 reload all
Forever is a simple CLI tool for ensuring that a given script runs continuously (i.e., forever). It is similar to PM2 but lacks some of its advanced features like application monitoring and load balancing.
Nodemon is a utility that monitors for any changes in your source and automatically restarts your server. It is often used in development environments, unlike PM2 which is tailored for production use.
StrongLoop Process Manager (strong-pm) is a production process manager for Node.js applications with features like remote deployment and performance monitoring. It is part of the StrongLoop suite, which is now owned by IBM.
Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. It is not specifically designed for Node.js and is more general-purpose.
The modern and stable CLI process manager for Node apps with native clusterization, monitoring, startup scripts and much more.
Tested with Node v0.12, v0.11, v0.10, v0.9, v0.8 (https://travis-ci.org/Unitech/pm2). Works on Linux & MacOS.
Blog post for some context : Goodbye node-forever, hello PM2
npm install -g pm2
# Usage/Features
$ npm install pm2 -g # Install pm2 command line globally
$ pm2 start app.js -i 4 # Daemonize pm2 and Start 4 clustered instances of app.js
# You can also pass the 'max' params to start
# the right numbers of processes depending of CPUs
$ pm2 list # Display all processes status
$ pm2 monit # Monitor all processes
$ pm2 logs # Display all processes logs in streaming
$ pm2 dump # Dump the states of all processes
$ pm2 stop pm2_id # Stop specific process id
$ pm2 stopAll # Stop all processes
$ pm2 resurrect # Put online previously dumped processes
$ pm2 restart pm2_id # Restart specific process
$ pm2 restartAll # Restart all proccesses
$ pm2 stopAll # Stop all processes
$ pm2 generate app # Generate a JSON process configuration
$ pm2 startup # Generate init script to keep processes alive
$ pm2 web # Health computer API endpoint (http://localhost:9615)
## Different ways to launch a process
$ pm2 start app.js -i max # Will start maximum processes depending on CPU availables
$ pm2 start app.js -i 3 # Will start 3 processes
$ pm2 start app.json # Start processes with options declared in app.json
# Go to chapter Multi process JSON declaration for more
$ pm2 start app.js -c "* * * * * *" # Will restart the process depending on the
# cron pattern. Here it will restart the process
# every second
$ pm2 start app.js -i max -- -a 23 # Pass arguments after -- to app.js
$ pm2 start app.js -i max -e err.log -o out.log -w # Will start and generate a configuration file
## Is my production server ready for PM2 ?
Just try the tests before using PM2 on your production server
$ git clone https://github.com/Unitech/pm2.git
$ cd pm2
$ npm install # Or do npm install --dev if devDependencies are not installed
$ npm test
If a test is broken please report us issues here
## Updating pm2 and keeping processes alive$ pm2 dump
$ npm install -g pm2@latest
$ pm2 kill ; pm2 resurrect
npm install git://github.com/Unitech/pm2.git -g
## pm2 list
List infos about all processes managed by pm2. It shows also how many times a process has been restarted because of an unhandled exception.
## pm2 monitMonitor CPU and memory usage of every node process (and also clustered processes) managed by pm2.
## pm2 automatic startup script generationPM2 provides an automatic way to keep Node processes alive. It uses an init script (compatible with most Linux systems).
$ pm2 startup
Now you can reboot your server, and already launched processes should be kepts alive ;)
## pm2 logsDisplay logs in streaming of all processes, without having to do a tail -f or something else.
## pm2 dump/resurrectYou can dump all currently running processes, including their environment and execution path.
After restarting or stopping PM2 you can resurrect
them.
The -c "cron_pattern"
option permits to hard restart a process scheduled on the cron pattern.
Look at test/cli.sh for examples.
PM2 can disserve an API endpoint to monitor processes and computer health (cpu usage, memory, network interfaces...)
pm2 web
# Multi process JSON declaration
processes.json :
[{
"name" : "echo",
"script" : "./examples/args.js",
"instances" : "1",
"args" : "['--toto=heya coco', '-d', '1']",
"cron_restart" : "* * * * * *"
},{
"name" : "api",
"script" : "./examples/child.js",
"instances" : "4"
},{
"name" : "bus",
"script" : "./examples/echokill.js"
}]
Then with the cli :
$ pm2 start processes.json
# Test
npm test
You can install processes and communicate with them
$ m2 install web-pm2
$ m2 list
$ m2 start web-pm2
$ m2 info web-pm2 # list
Thanks to Devo.ps and Wiredcraft for their knowledge and expertise.
# License - Apache License v2Copyright [2013] [Strzelewicz Alexandre as@unitech.io]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Production process manager for Node.JS applications with a built-in load balancer.
The npm package pm2 receives a total of 2,118,811 weekly downloads. As such, pm2 popularity was classified as popular.
We found that pm2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.