Step 1 – Install Node.js

First, you need to node.js PPA in our system provides by the nodejs official website. We also need to install the python-software-properties package if not installed already. After adding the required PPA file let’s install the Nodejs package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

Step 2 – Install PM2

Now, Use npm to install the process manager for Node.js using the following command. This will install the latest version of pm2 on your system.

Step 3 – Start Application with PM2

Now create a PM2 configuration file. For this tutorial, I have two Node.js applications to host on the production server. The source code applications are available under /var/www/parse-apps/app1 and /var/www/parse-apps/app2 directories. Create a configuration file parse-apps.config.js with the following content. Both applications have an index.js startup JavaScript file to run my application. Now use the following command to start the application with pm2. In the below command, we are passing the parse-apps.config.js configuration file name. PM2 will read the configuration file and start all applications and assign a unique id.

Step 4 – Manage Processes with PM2

To list all processes registered under PM2 using the following command. This will also display the status of the application, process id, and other useful information. To view more details of the specific process, you can use the below command followed by id or process app name.

You can also monitor all processes CPU and memory uses in real-time.

How to Deploy Node js Application using PM2   TecAdmin - 47How to Deploy Node js Application using PM2   TecAdmin - 33How to Deploy Node js Application using PM2   TecAdmin - 75