Skip to content

PM2 Deployment

PM2 is a popular process manager for Node.js applications. It allows you to keep your applications alive forever, reload them without downtime, and facilitate common system admin tasks. PM2 is designed to be a simple and efficient tool to manage and monitor your Node.js applications.

Installation

  • To install PM2, you need to have Node.js and npm (Node Package Manager) installed on your system.

  • Open the command prompt with administration privileges and user can install PM2 globally using npm with the following command:npm install pm2 -g

Screenshot

  • List all running processes using the command: pm2 ls

Screenshot

  • Copy the path manually from folder for which application you want to run with PM2.

Screenshot

  • Open the command prompt with administration privileges and paste the copied path with command: cd copied_path

Screenshot

Example

In this example, we are using an application called Code Management. We will use the index.js file to run PM2, as it is the main file of the Code Management application. Users should replace index.js with the main file of their own application.

  • Start your application assigning a name using PM2 command: pm2 start index.js --name="CodeManagement"

Screenshot

  • Save the current process list using command: pm2 save

Screenshot

  • Now user can view the saved application in PM2 using command: pm2 ls

Screenshot

Managing Applications with PM2

  • Suppose user needs to restart a specific application, use it's Id or name, the command is: pm2 restart 0 or pm2 restart CodeManagement

Screenshot

-Suppose user needs to stop a specific application, use it's Id or name, the command is: pm2 stop 0 or pm2 stop CodeManagement

Screenshot

  • Resurrect processes from the last saved list using command: pm2 resurrect

Screenshot

  • Restart all applications using command: pm2 restart all

Screenshot

  • Suppose user needs to delete a specific application, use it's Id or name, the command is: pm2 delete 0 or pm2 delete CodeManagement

Screenshot