From Keymetrics to PM2 +
Keymetrics is the new PM2 Plus. Here is the story about the "why?". Here we are more than 5 years after the first commit on the PM2 open source project. Which is now de facto process manager for Node.js
Using PM2 is straightforward, install it via Yarn or NPM, start your application and get in full control
# Baremetal installation npm install -g pm2 pm2 start app.js # Docker love RUN npm install pm2 -g CMD ["pm2-runtime", "app.js"]
# Start in production mode pm2 start api.js worker.js # List applications pm2 list # Restart them all pm2 restart all # Delete that api pm2 delete worker
# Display logs from app pm2 logs pm2 logs app # Magic Command: Automatic Logrotate pm2 install pm2-logrotate
# Create and load balance 4 instances of app.js pm2 start app.js -i 4 # Or load balance with the maximum cores of your CPU pm2 start app.js -i max # Achieve a 0-second-downtime reload. pm2 reload app
# Setup deployment at remote location $ pm2 deploy production setup # Update remote version $ pm2 deploy production update # Revert to -1 deployment $ pm2 deploy production revert 1 # execute command on remote machines $ pm2 deploy production exec "pm2 reload all"
We crafted a lovely documentation that you can consider like the Bible of PM2. Even better, this is a searchable Bible.
Guides, Integrations, best practices and much more.
Once started, your app is forever alive, auto-restarting across crashes and machine restarts.
Startup scripts are generated with `pm2 startup`.
Run and manage your processes easily. Take full control of your Node.js application running in the background.
Monitor your app in the terminal to check your app health (CPU usage, memory used, request/min and more).
Don't spend hours finding and classifying your application logs, PM2 does it intelligently for you.
As Node.js is monothreaded, PM2 automatically duplicates the processes to use all the cores for your CPUs.
Thanks to this, you can also restart your app with zero-seconds downtimes.
Don't ssh one by one in all your servers anymore. PM2 gives you the possibility to deploy your apps remotely.
Look how to configure it.