Introduction
This would be a series of articles, in this article, we would talk about the deployment of the NESTJS application on AWS.
It will cover the following things,
- What is NestJS? (covered in the first article)
- Background (covered in the first article)
- Installation(covered in the first article)
- Hands-on Lab – Create a sample NestJS project (covered in the first article)
- In-depth Explanation - Out-of-the-box files(covered in the second article)
- Hands-on Lab – Create custom APIs and connect with the PostgreSQL database in the existing NestJS project (covered in the third article)
- Hands-on Lab –Deploy NestJS application on AWS
Hands-on Lab - Deploy NestJS application on AWS
Open Visual Studio Code with the existing application, create a Procfile for the AWS pipelines to refer to, and see the file and its code –
web : npm run deploy

Once Procfile is created and the deploy command is mentioned there, then we need to create a deploy command in the package.json file, have a look at the below code
"deploy": "npm ci && npm run build && npm run start:prod"

Once, this is done, we would move to main.ts and define the environment variable as PORT and changes in the code, have a look below,
import { NestFactory } from'@nestjs/core';
import { AppModule } from'./app.module';
asyncfunctionbootstrap() {
constapp = awaitNestFactory.create(AppModule);
constport = process.env.PORT || 3000;
awaitapp.listen(port);
}
bootstrap();
Now, execute the following to check if the APIs is working fine or not, below is the command, followed with response
npm run deploy









Join the conversation! Your thoughts help the community grow.