How to Setup PM2 on Ubuntu 18.04

PM2 is a very popular process manager for the Node.js JavaScript environment. PM2 was ranked 82nd most popular JavaScript project on GitHub in 2016. This daemon manager includes a huge set of functions, some of which will be listed below:

  1. BEHAVIOR CONFIGURATION
  2. SUPPORT SOURCE MAP
  3. INTEGRATION OF CONTAINERS
  4. WATCH AND RELOAD
  5. LOG MANAGEMENT

In this article, we will try to find out how you can install PM2 and run the basic setup on Ubuntu 18.04.

Installing PM2 via NPM

Installing PM2 is very simple and can be done with one line of code.

npm install -g pm2

Setting up PM2 to run your project

Start by navigating to your project directory. You can do this by typing the cd command followed by a directory.

cd /root/project

To start the application, enter the command pm2 start and then specify the location of your application

pm2 start /project/app.js

Next, you will be presented with a table that you can see below:

Launch PM2 as a Service

After running the above code, it is recommended that you configure PM2 as a service so that it can start when the server starts.

env PATH=$PATH:/usr/local/bin pm2 startup -u root

Be sure to replace root with your username if you are not using it as root

Was this article helpful?

Related Articles