Deploy Nest JS App using PM2 to Linux Server

Hi guys, in this article I will show you how to deploy Nest JS application to Linux Server. For this tutorial I use Ubuntu 20.04 LTS.

STEP 1 (Install Node JS)

First, you need to install Node JS on your ubuntu server using this command :

STEP 2 (Install Nest JS CLI)

After that, to run and build Nest JS App you need to install Nest JS CLI using this command :

STEP 3 (Install PM2)

PM2 is a library

STEP 4 (Clone your project from Source Control)

You have Node JS, Nest CLI and PM2 installed in your server, now you can clone your project from The Source Control Repository to a folder :

STEP 5 (Run project)

After downloading all packages on your project, you need to build your Nest JS Project first :

If the build success, it will generate folder /dist on the root directory. Run your application using this command :

In the code above, You can specify the application_name as you want. To make your application autostart after system reboot, use this command :

Now your Nest JS application has been successfully deployed to Ubuntu Server. Enjoy!