In this article, I will cover steps that will help you to deploy Nest JS application on Linux Server. I am using Ubuntu 20.04 LTS **during writing this article and I am assuming you have already installed **Node.js on your server.
Generally, we use npm i command to run all the dependencies but that will not install Nest JS so we have to manually install Nest JS CLI
$ sudo npm i -g @nestjs/cli
If you didn’t install PM2 earlier then you have to use following command to install PM2.
$ sudo npm install pm2@latest -g
If you want to get more details about PM2 commands, then please visit url: PM2 Commands
You can clone your repo using following command and install necessary dependencies. If you want more details on Cloning, please refer article: Clone Specific Git Branch
$ git clone http://coderepo.com/projectname.git
$ cd projectname
$ npm install
For Nest JS app, you have to first generate a build then only you can run the project on server.
$ npm run build
If build is generated successfully then will create /dist folder under root directory. Now you can run your project using following PM2 command
$ pm2 start dist/main.js --name <application_name>
application_name you can use to give unique app name so that you can easily identify your apps in pm2 list.
There are some PM2 commands to make your application auto restart after system reboot also
$ pm2 startup systemd
$ pm2 save
I hope this article will help you deploy your Nest JS application on Linux Server. If you liked the solution, please hit the Clap button or comment if you have any suggestion or feedback.