How to Use Pm2 To Serve A Node.js App

How to Use Pm2 To Serve A Node.js App

Learn how to use pm2 to serve a Node.js app. PM2 is a super useful process management tool for Linux. The deployment/running of the application is already managed through the pm2 program. You can use pm2 list to see all the applications running now. Make sure you ssh as the Node.js user.

An introduction on how to manage Node processes on Linux and auto-restart them through GitHub webhooks

Published Mar 03, 2021

pm2 is a super useful process management tool for Linux.

I’ve used it for several projects of mine, and here I want to tell you how to use it too!

In particular I’m going to use it to run a Node.js app on a DigitalOcean VPS, and I’ll set it up so that whenever we push an update to the app’s GitHub repository, on the server pm2 will be pinged, and the app is going to be updated from GitHub and restarted.

Sounds cool? Let’s go!

First, sign up to DigitalOcean and  follow my tutorial to create an VPS on DigitalOcean.

Important: use the `NodeJS_` image on DigitalOcean, which is already set up with `pm2__ and _node_`, and has a `nodejs__ user in addition to _root_`._

Once you’re up and running we can start.

Make sure you ssh as the nodejs user. When you’re logged in as root, you can just run su nodejs to use that user.

The sample Node.js app you have running in the VPS is in the folder /var/www/html/, and it’s composed by the hello.js file.

The deployment/running of the application is already managed through the pm2 program, a daemon process manager.

You can use pm2 list to see all the applications running now:

If you do any change to the application now, the changes won’t be applied until you restart the application running:

pm2 restart hello

node.js node

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Hire Top Node JS Developers | Best Node.js Development Company India

Hire dedicated Node JS developers & programmers in India for custom full-stack NodeJS web development projects on hourly/full-time basis. Strict NDA, 16+ years exp & 2500+ clients|450+ Experts

Hire Dedicated Node.js Developers - Hire Node.js Developers

Get business-centric Node.Js development services from expert Node.JS developers. We have expertise in developing & maintaining Node JS apps as per the business requirements.

Node JS Development Company| Node JS Web Developers-SISGAIN

SISGAIN is the top rated node js development company providing professional services on node js web and mobile development.

Why use Node.js for Web Development? Benefits and Examples of Apps

Get Node.js developers & programmers, and dedicated Node coders in India with average 5 years of experience. 15+ Yrs Exp, 500+ Staff, 13800+ Projects, 6800+ Clients.

Node JS Development Company | Hire Node.js Developers

Looking to hire Node js developers? One of the top Node js development companies in India & USA offers cost-effective Node js web development services.