DEV Community

Chandra Prakash Pal
Chandra Prakash Pal

Posted on • Edited on

PM2 Add NodeJs Project In Process List

During the NodeJs project deployment we use the PM2 as process manager.

PM2 monitor the application and restart it automatically while if app is crashing.

First install PM2 package

`$ npm install pm2@latest -g

or

$ yarn global add pm2`

When managing multiple applications with PM2, use a JS configuration file to organize them.

To generate a sample configuration file you can type this command:

pm2 init simple

This will generate a sample ecosystem.config.js:

module.exports = {
apps : [{
name : "app1",
script : "./app.js"
}]
}

Now the command to add NodeJs project in pm2 list with npm script are following way

pm2 start npm --name "{project_name}" -- run {script_name}

For Example ,let's i have a project with name HelloWorld and script to run the project are npm run dev the following command will be.

pm2 start npm --name "rStoreFront Backend" -- run dev

Here are some references for deploy nodejs project

How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04

How To Set Up a Node.js Application for Production on Ubuntu 20.04

Top comments (0)