Deploying NestJS Application: Easy and Explained
Nest: Quick Overview
The biggest rule of programming is--DRY (Don't Repeat Yourself).
If one wants to write a more efficient code whilst developing any kind of application, they must practice DRY and SOLID principles.
These principles are the base of the famous Model-View-Controller (MVC) design pattern. The Angular Framework for building Frontend is entirely based on this design pattern. It uses concepts of components and services to implement DRY and SOLID Principles.
Not only the increase in performance, understanding Angular code is quite easy due to this.
There was no backend framework that makes the task easy in the same way as Angular does in frontend. That's where Nest originated.
Nest is a backend framework that is heavily inspired by Angular.
- It uses the concepts of services, controllers, and modules to implement MVC pattern in a way similar to Angular.
I highly recommend using Nest when working on larger projects rather than using Express.
The focus of this article is on the deployment of Nest Applications, if you want me to post beginner or advanced level tutorials on learning Nest.js, comment below:-)
How to Deploy NestJS Application?: The Theory
How to Deploy NestJS Application?: The Platform Generic Steps
- First, open
package.jsonmake sure that it contains scripts defined as
"build": "nest build", "start": "nest start", "start:prod": "node dist/main",
Some Hosting Providers use Procfile for running web applications, so create a file in the project folder named
Procfileand add the following single line to it.
web:npm run start:prod
- Delete the
distfolder and run
npm run startin command-line/terminal to create the latest version of compiled output files. (Deleting folder first is not necessary but it has proven helpful in some cases).
- Push your changes to GitHub Repository using these three basic commands:
git add . //Stage All Files including dist folder git commit -m "Commit Message" git push
- Setup your cloud instance on any platform:
- Clone the GitHub repository to the instance using the terminal.
- Target your server to launch
dist/main.jsif required to specify.
In this way, your NestJS app will be deployed.
This process is attested and followed by developers of era-co.in
Thanks for Reading! What should I post about next? Do tell me in the comments. Suggestions, improvements, and additions are invited.