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
- List all running processes using the command:
pm2 ls
- Copy the path manually from folder for which application you want to run with PM2.
- Open the command prompt with administration privileges and paste the copied path with command:
cd copied_path
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"
- Save the current process list using command:
pm2 save
- Now user can view the saved application in PM2 using command:
pm2 ls
Managing Applications with PM2
- Suppose user needs to restart a specific application, use it's Id or name, the command is:
pm2 restart 0
orpm2 restart CodeManagement
-Suppose user needs to stop a specific application, use it's Id or name, the command is: pm2 stop 0
or pm2 stop CodeManagement
- Resurrect processes from the last saved list using command:
pm2 resurrect
- Restart all applications using command:
pm2 restart all
- Suppose user needs to delete a specific application, use
it's Id or name, the command is:
pm2 delete 0
orpm2 delete CodeManagement