Run Your Production Node Applications using PM2
Just entering the Node.js world? Even as a veteran, choosing modules to rely on in production can be a little intimidating.
One really polished and well-documented package I've come across is the PM2 module. You use PM2 to run your Node application in production.
When running your program with PM2 it will restart automatically when a crash or exception happens. Additionally, you can can view a really slick monitor display showing your all your apps and their current status and info. PM2 also makes running your Node.js applications in cluster mode incredibly easy.
Let's go over some of the commands I use on my applications. Make sure you have PM2 and Node installed.
First you're going to want to create an file in the root of your project. Use the following json as a template for you're program.
Your file is the configuration file that PM2 will use when dealing with your app.
To start your app the code is very simple:
Then to stop your app later just run
Once running, you can view all your apps with or enter the monitoring mode by using . To view information on your app run followed by your app name from the config file.
Super simple and reliable - and the documentation is clearly written - which is a huge plus. Make sure to read through the details as this is just scratching the surface of what PM2 is capable of.