Learn How To Setup PM2 on Ubuntu 16.04

August 16, 2019

Table of Contents

PM2 is a very popular Node process manager that makes running NodeJS applications easy. PM2 makes it easy to restart apps, automatically restart crashed applications and automatically start applications after a server reboot.

This article will teach you how to install PM2 and run basic setup on Ubuntu 16.04.

Prerequisites

https://www.itweb.services/tutorials/linux-guides/installing-node-js-and-express” title=”Learn to Install NodeJS and Express”>here (ExpressJS is not strictly required)

This tutorial also assumes that you are logged in as root. If you do not have access to the root user, add sudo to the start of all commands.

Installing PM2 via NPM

Installing PM2 is very simple, and can be done in a single 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 the directory.

cd /root/project

To start your app, type the command pm2 start followed by your app’s location.

pm2 start /project/app.js

You will see a table that resembles the following image.

Running PM2 as a service

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

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

Make sure to replace root with your username if you aren’t using the root user.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!