description PM2 (Process Manager 2) Overview
PM2 is the gold standard process manager specifically for Node.js applications. It handles auto-restarting, logging, and clustering for Node apps with remarkable ease. It allows developers to define processes that automatically restart upon failure and can manage multiple instances across CPU cores, ensuring high performance and uptime for JavaScript backends without complex setup.
help PM2 (Process Manager 2) FAQ
How do I start a Node.js application using PM2?
You can start an application by running the command `pm2 start app.js` in your terminal. PM2 will immediately push the process to the background and manage its lifecycle.
How does PM2 ensure my application restarts after a crash or server reboot?
PM2 monitors the process and will automatically restart it if it crashes or exits unexpectedly. To survive a server reboot, you simply run the `pm2 startup` command to generate and install a system startup script.
Does PM2 support clustering for Node.js apps out of the box?
Yes, you can enable cluster mode by passing the `-i` flag followed by the number of instances, such as `pm2 start app.js -i max`. This spins up multiple worker processes across all available CPU cores to balance the load.
How can I view the logs of an application managed by PM2?
You can view real-time logs by running the `pm2 logs` command in your terminal. PM2 automatically aggregates logs from all managed applications into specific files located in the `~/.pm2/logs` directory.
explore Explore More
Similar to PM2 (Process Manager 2)
See all arrow_forwardReviews & Comments
Write a Review
Be the first to review
Share your thoughts with the community and help others make better decisions.