How can I start my NestJs application on amazon EC2 instance - node.js

I'am trying to deploy my NestJs application on an EC2 instance.
I cloned my project and installed all dependencies but then when I tried to start the app, it can't initialize all dependencies (can't even reach TypeOrmCoreModule dependencies).
I have no errors.
[Nest] 117257 - 09/27/2021, 1:14 AM [NestFactory] Starting Nest application...
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] TypeOrmModule dependencies initialized +176ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] PassportModule dependencies initialized +0ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] NeconfigModule dependencies initialized +1ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] JwtModule dependencies initialized +0ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] CommentsModule dependencies initialized +0ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] MsPostsModule dependencies initialized +1ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] PostCommentsModule dependencies initialized +0ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] ConfigModule dependencies initialized +11ms
[Nest] 117257 - 09/27/2021, 1:14 AM [InstanceLoader] AppModule dependencies initialized +1ms
I my local machine the Nest application is successfully started.
[Nest] 15660 - 27/09/2021, 03:10:58 [NestFactory] Starting Nest application...
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +112ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] PassportModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] NeconfigModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] JwtModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] CommentsModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] MsPostsModule dependencies initialized +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] PostCommentsModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmCoreModule dependencies initialized +236ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] NotificationModule dependencies initialized +16ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] PostContentModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] FollowersTsModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] FavorisModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] PostModule dependencies initialized +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] AccountModule dependencies initialized +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [InstanceLoader] UsersModule dependencies initialized +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] AppController {/}: +8ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/facebook, GET} route +3ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/facebook/redirect, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/authorize_user, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/handleauth, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/handleauthcode, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/google, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/google/redirect, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] UsersController {/users}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/createUser, POST} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/:id, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/search/:email, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/:id, PUT} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/:id, DELETE} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/login, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/confirm/:id, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/resetPassword, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/changePassword/:id, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/follow, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/unfollow, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/inst, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/googlelogin, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/facebooklogin, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/testTypeCnx/:id, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] NotificationController {/notification}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/addNotif, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getNotif, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] CommentsController {/comments}: +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] MsPostsController {/ms-posts}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] AccountController {/account}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/createOneAccount, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getAllUser, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getUserByName/:userName, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/UpdateUser/:userName, PUT} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/DeleteByUsername/:userName, DELETE} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/addFromxlsx, POST} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/showAllUsername, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getBestAccountLastMonth, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getBestAccountLastYear, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getRankAccountLastWeek, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getBestAccountByDay, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getRank/:starName/:dateTest, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getFollowersByDay/:userName, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getFollowersByMonth/:starName, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getFollowersByweek/:starName, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/compare/:starName1/:starName2, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/createData/:starName/:fieldScrape/:countryScrape, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] PostController {/post}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/allPosts, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/country, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/username/:userName/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/Rankingpermonth/:month/:year/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/:userName/Rankingpermonth/:month/:year/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/maxMonth, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/avgLikesMonth, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/avgCommentMonth, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/RankingLastweek/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/:userName/RankingLastweek/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/Rankingperyear/:year/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/:userName/Rankingperyear/:year/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/totalYear, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/maxYear, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/likesYear/:year/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/likesMonth/:year/:month/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/likesAllTimes/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/celeblikesAllTimes/:userName/:skip, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/celeblikesByMonth/:userName/:year/:month, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/celeblikesByYear/:userName/:year/:skip, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/avgCommentYear, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/maxCommentYear, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] PostContentController {/postContent}: +0ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/postId, GET} route +3ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] PostCommentsController {/post-comments}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] FavorisController {/favoris}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/addFavoris/:idUser, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getAllFavoris/:idUser, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/addFavorisToAccount/:idUser/:starName, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/checkFavorit/:idUser/:starName, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/FavorisByYear/:idUser, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/FavorisByMonth/:idUser, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/FavorisByDay/:idUser, GET} route +3ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/fovorisAll/:idUser, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/deleteFavoris/:idUser/:starName, DELETE} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/FavorisByWeek/:idUser, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RoutesResolver] FollowersTsController {/followers-ts}: +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/insertDataToDataBase/:username, POST} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getAllData/:starName, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getDataofSpecificDate/:starName, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getAccountLastYear, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getAccountLastMonth, GET} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/getAccountLastWeek, GET} route +2ms
[Nest] 15660 - 27/09/2021, 03:10:58 [RouterExplorer] Mapped {/scrappingInsta/:starName/:fieldScrape/:countryScrape, POST} route +1ms
[Nest] 15660 - 27/09/2021, 03:10:58 [NestApplication] Nest application successfully started +9ms
And this is my main.ts file
import { NestFactory } from '#nestjs/core';
import { AppModule } from './app.module';
import * as dotenv from "dotenv";
import * as http from 'http';
import * as express from 'express';
const fs = require('fs');
dotenv.config();
async function bootstrap() {
const server = express();
const app = await NestFactory.create(
AppModule,
);
app.enableCors({
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"allowedHeaders" : ['Content-Type']
});
await app.init();
http.createServer(server).listen(3005);
}
bootstrap();
I can't figure out why the app can't be started successfully in the ec2 instance.

Related

Nest JS mapping unknown Routes

[Please review the screenshot..
why these
[Nest] 3648 - 21/05/2022, 8:14:07 am LOG [RouterExplorer] Mapped {/auth, POST} route +1ms
[Nest] 3648 - 21/05/2022, 8:14:07 am LOG [RouterExplorer] Mapped {/auth, GET} route +1ms
[Nest] 3648 - 21/05/2022, 8:14:07 am LOG [RouterExplorer] Mapped {/auth/:id, GET} route +1ms
[Nest] 3648 - 21/05/2022, 8:14:07 am LOG [RouterExplorer] Mapped {/auth/:id, PATCH} route +1ms
[Nest] 3648 - 21/05/2022, 8:14:07 am LOG [RouterExplorer] Mapped {/auth/:id, DELETE} route +1ms
]1
enter image description here

Controller methods not being mapped in nestjs

I have a nestjs module called AuthModule
import { Module } from '#nestjs/common';
import { AuthService } from './auth.service';
import { TypeOrmModule } from '#nestjs/typeorm';
import { UsersEntity } from './user-auth-credentials.entity';
import { UsersRepository } from './users.repository';
import { AuthController } from './auth.controller';
#Module({
imports: [TypeOrmModule.forFeature([UsersRepository])],
controllers: [AuthController],
providers: [AuthService],
})
export class AuthModule {}
a controller called **AuthController**.
import { Controller, Get } from '#nestjs/common';
import { AuthService } from './auth.service';
#Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
#Get()
findAll() {
return 'Hello World';
}
}
The methods in the controller findAll as an example are not being mapped during compiling as shown by the output of npm run start:dev below.
[12:36:39] File change detected. Starting incremental compilation...
[12:36:39] Found 0 errors. Watching for file changes.
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [NestFactory] Starting Nest application...
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] TypeOrmModule dependencies initialized +122ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +73ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] AuthModule dependencies initialized +0ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [InstanceLoader] TeachersModule dependencies initialized +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RoutesResolver] AppController {/}: +7ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RouterExplorer] Mapped {/, GET} route +4ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RoutesResolver] TeachersController {/teachers}: +0ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RouterExplorer] Mapped {/teachers, GET} route +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RouterExplorer] Mapped {/teachers/id, GET} route +2ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RouterExplorer] Mapped {/teachers, POST} route +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RouterExplorer] Mapped {/teachers/id, PATCH} route +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RouterExplorer] Mapped {/teachers/id, DELETE} route +1ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [RoutesResolver] AuthController {/auth}: +0ms
[Nest] 4262 - 09/03/2022, 12:36:40 LOG [NestApplication] Nest application successfully started +4ms
When I access the route using Insomnia i get this
output of Insomnia
Is there something Im not doing right?
your code looks fine but the output didn't show any Mapped {/auth, GET}. I'd say that you're probably running an old version of the your code (which doesn't have that findAll method)
Try rm -rf dist and start it again.

Path based routing for Microservices in AWS ECS with API Gateway

We are deploying node microservices for the first time in AWS ECS and each services are listening on dynamic ports.
The following are the APIs of the microservices exposing while starting the node application.
ANIMAL MicroService
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/animal/:id, GET} route +2ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/animal/getAll, GET} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/animal, POST} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/animal/:id, PUT} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/animal/:id, DELETE} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RoutesResolver] dogPlanController {/dog}: +0ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/dog/:id, GET} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/dog, POST} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/dog/:id, DELETE} route +1ms
Bird MicroService
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/bird/:id, GET} route +2ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/bird/getAll, GET} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/bird, POST} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/bird/:id, PUT} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/bird/:id, DELETE} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RoutesResolver] eaglePlanController {/eagle}: +0ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/eagle/:id, GET} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/eagle, POST} route +1ms
[Nest] 29 - 12/22/2020, 8:12:30 AM [RouterExplorer] Mapped {/eagle/:id, DELETE} route +1ms
Users MicroService
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/healthcheck, GET} route +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RoutesResolver] SsoController {/sso}: +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/sso, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RoutesResolver] AuthController {/auth}: +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/signup, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/sendotp, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/verifyOtp, POST} route +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/login, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/duplicateUserName, GET} route +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/resetPasswordOtp, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/auth/resetPassword, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RoutesResolver] UserController {/user}: +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user/questionnaire/:id, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user/questionnaire/:id, GET} route +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user/:id, GET} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user, GET} route +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user/userList, POST} route +1ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user/connectWearable, POST} route +0ms
[Nest] 28 - 12/21/2020, 11:29:32 PM [RouterExplorer] Mapped {/user/getArticles, POST} route +1ms
Backend MicroService
[Nest] 29 - 12/22/2020, 12:02:28 AM [RoutesResolver] AuthController {/auth}: +1ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/auth/signup, POST} route +0ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/auth/login, POST} route +1ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RoutesResolver] animalController {/animal}: +0ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/animal/color, GET} route +1ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/animal/color, POST} route +0ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/animal, GET} route +1ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/animal, POST} route +1ms
[Nest] 29 - 12/22/2020, 12:02:28 AM [RouterExplorer] Mapped {/animal/:id, DELETE} route +0ms
..
..
..
..
Developers are expecting the following routing.
Note: carefully observe the routing they are requesting.
For ANIMAL MicroServices,
example.com/animal -->> animal-microservice-url/animal
example.com/animal/dog -->> animal-microservice-url/dog
For USER MicroServices,
example.com/user -->> user-microservice-url/user
example.com/user/auth -->> user-microservice-url/auth
example.com/user/sso -->> user-microservice-url/sso
Can someone help me to achieve this in AWS environment.?
I tried ALB path based routing which wasn't fruitful given the scenario as ALB doesn't strip off the postfixes in alburl.
I have also tried API Gateway with ALB. I setup few ALB path based routes such that it can accept requests from apigateway & forward them to target groups.
However, I'm experiencing trouble while setting `wildcard, *, in ALB path based routing' alike in APIGateway to route all postfixes to one url.
example:
apigatewayurl.com/animal -->> alburl.com/animal
apigatewayurl.com/animal/dog -->> alburl.com/dog
The above two are working fine.
But the following are not.
apigatewayurl.com/animal/:id -->> alburl.com/animal/:id
apigatewayurl.com/animal/getAll -->> alburl.com/animal/getAll
apigatewayurl.com/animal/dog/:id -->> alburl.com/dog/:id
How can I create an HTTP API route such that it access all the postfixes in alburl from apigatewayurl?
Like, when I enter apigatewayurl.com/animal/dog/* -->> alburl.com/dog/*
I tried present the issue as possible as I can.
Please feel free to ask about configuration.
If this can be done via any other service in AWS, please suggest me here.
I don't think its possible. because here ALB just checks path, it just verifies whether given path is equal to the one mention there , it cant accept values.. You are sending values in URL.
My suggestion is that - send id or your data values in body of your request ,instead sending those in request URL. and catch those value in your API

Don't see console.log() or logger messages while running nestjs and hitting any end point

I don't see any status or console messages in the IDE console while trying to hit any end-point. I do see the response getting returned but no call details in the console. I am confused as why is it behaving this way?
Following is what I see on running npm run-script start:dev -
> nest start --watch
[3:04:44 PM] Starting compilation in watch mode...
[Nest] 14340 - 05/20/2020, 3:10:58 PM [NestFactory] Starting Nest application...
[Nest] 14340 - 05/20/2020, 3:10:58 PM [InstanceLoader] TypeOrmModule dependencies initialized +220ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [InstanceLoader] TypeOrmCoreModule dependencies initialized +195ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [InstanceLoader] TypeOrmModule dependencies initialized +6ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [InstanceLoader] AppModule dependencies initialized +5ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RoutesResolver] AppController {}: +13ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {, GET} route +4ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RoutesResolver] BatchController {/batch}: +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/batch, POST} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/batch, GET} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/batch/:batch, GET} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/batch/:batch, DELETE} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RoutesResolver] StudentController {/student}: +0ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/student, POST} route +2ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/student, GET} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/student/:id, GET} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:58 PM [RouterExplorer] Mapped {/student/:id, DELETE} route +2ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RoutesResolver] AssignmentController {/assignment}: +1ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RouterExplorer] Mapped {/assignment, POST} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RouterExplorer] Mapped {/assignment, GET} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RouterExplorer] Mapped {/assignment/:id, GET} route +2ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RouterExplorer] Mapped {/assignment/:id, DELETE} route +1ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RoutesResolver] UploadController {/upload}: +1ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [RouterExplorer] Mapped {/upload, POST} route +2ms
[Nest] 14340 - 05/20/2020, 3:10:59 PM [NestApplication] Nest application successfully started +3ms
When I hit http://localhost:3000/batch, I see the response but the console above doesn't display anything like API type GET or status 200 etc.
This is what I have in controller -
import {
Controller,
Get,
Post,
Body,
Param,
Delete,
Logger,
} from '#nestjs/common';
import { BatchService } from './batch.service';
import { Batch } from './batch.entity';
import { InsertResult } from 'typeorm';
#Controller('batch')
export class BatchController {
private readonly logger = new Logger(BatchController.name);
constructor(private batchService: BatchService) {}
#Post()
create(#Body() batchDto: Batch): Promise<InsertResult> {
this.logger.log(':: BatchController :: create()');
console.log(':: BatchController :: create()');
return this.batchService.create(batchDto);
}
#Get()
findAll(): Promise<Batch[]> {
this.logger.log(':: BatchController :: findAll()');
console.log(':: BatchController :: findAll()');
return this.batchService.findAll();
}
#Get(':batch')
findOne(#Param('batch') batchName): Promise<Batch> {
this.logger.log(':: BatchController :: findOne()');
console.log(':: BatchController :: findOne()');
return this.batchService.findOne(batchName);
}
#Delete(':batch')
remove(#Param('batch') batchName) {
this.logger.log(':: BatchController :: remove()');
console.log(':: BatchController :: remove()');
return this.batchService.remove(batchName);
}
}
Put the console and logger both as to see if anything works.
It seems like you have the logs disabled for your NestJS Application.
The best and simple way to enable NestJS request logging is to use its built-in logger service.
To do that, you can pass an array of LogLevels when bootstrapping a NestJS Application.
In your main.ts OR wherever you are bootstrapping the Nest app,
const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(), {
cors: true,
logger: ['error', 'warn', 'log'] // <--- Add this line in options object
});
Here, pass an array of LogLevels in options.logger.
As of now, LogLevel type has these applicable values:
declare type LogLevel = 'log' | 'error' | 'warn' | 'debug' | 'verbose';
(code snippet taken from #nestjs/common)
Now run the project again and it should print request logs in console.
Almost sure that there are some host settings that prevent the normal behavior. I will contact my hosting provider to understand it, but how did i get to that information:
My NestJS app stopped to send emails. I implemented Logger from NestJS tutorial - No output.
I have added console.log/error - no output
I have removed all my app files from host and left only 1 app.js file with a simple code snippet:
const http = require("http");
const port = 80;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello World");
});
server.listen(port, () => {
console.log("I WILL BE LOGGED1?");
process.stdout.write("I WILL BE LOGGED2?");
process.stderr.write("I WILL BE LOGGED3?");
});
And noticed that only "process.stderr.write" gets logged no matter what you do. So currently i'm using only that piece of code to log info.
I was not able to get either console.log nor this.logger.log to work. After some sanity checking, it appeared to be a cacheing issue.
In my case the solution was much simpler. I had to:
delete the /dist folder and
re-run npm run start:dev
Both console.log(...) and this.logger.log(...) instance I setup began working.

Nestjs Error: Cannot find module './app.controller'

I cant seem to locate where the error is coming from as the app compiled with Found 0 errors. Watching for file changes. I have seen similar resolve on StackOverflow but none seem to address the issue
Here is the stack trace
internal/modules/cjs/loader.js:797
throw err;
^
Error: Cannot find module './app.controller'
Require stack:
- C:\Users\DELL\Documents\DokunFiles\Nestjs\app\api\dist\src\app.module.js
- C:\Users\DELL\Documents\DokunFiles\Nestjs\app\api\dist\src\main.js
With the appModule below, the app controller is properly imported into the app module
app.module.ts
import { Module } from '#nestjs/common';
import { MongooseModule } from '#nestjs/mongoose';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
#Module({
imports: [MongooseModule.forRoot(process.env.MONGO_URI,
{
useNewUrlParser: true,
useUnifiedTopology: true
})
, UserModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
app.controller.ts
import { Controller, Get } from '#nestjs/common';
import { AppService } from './app.service';
#Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
#Get()
getHello(): string {
return this.appService.getHello();
}
}
Run:
npm run prebuild
or
rimraf dist
or
rm -rf dist/
And try again.
I had the same issue:
stanislas#yeji > nest start api -> master ! ? RC=130
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module './app.controller'
Require stack:
- /Users/stanislas/git/soundbase/api/dist/src/app.module.js
- /Users/stanislas/git/soundbase/api/dist/src/main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/Users/stanislas/git/soundbase/api/dist/src/app.module.js:13:26)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/stanislas/git/soundbase/api/dist/src/app.module.js',
'/Users/stanislas/git/soundbase/api/dist/src/main.js'
]
}
And noticed the controller was indeed not compiled:
stanislas#yeji > ll dist/src/ api -> master ! ?
total 48
-rw-r--r-- 1 stanislas staff 138B Apr 19 17:45 app.module.d.ts
-rw-r--r-- 1 stanislas staff 2.1K Apr 19 17:45 app.module.js
-rw-r--r-- 1 stanislas staff 753B Apr 19 17:45 app.module.js.map
-rw-r--r-- 1 stanislas staff 11B Apr 19 17:45 main.d.ts
-rw-r--r-- 1 stanislas staff 340B Apr 19 17:45 main.js
-rw-r--r-- 1 stanislas staff 290B Apr 19 17:45 main.js.map
drwxr-xr-x 5 stanislas staff 160B Apr 19 17:52 migration
But I noticed it worked as prod:
stanislas#yeji > npm run build && npm run start:prod api -> master ! ? RC=1
> soundbase-api#0.0.1 prebuild /Users/stanislas/git/soundbase/api
> rimraf dist
> soundbase-api#0.0.1 build /Users/stanislas/git/soundbase/api
> nest build
> soundbase-api#0.0.1 start:prod /Users/stanislas/git/soundbase/api
> node dist/main
[Nest] 95175 - 04/19/2020, 6:40:45 PM [NestFactory] Starting Nest application...
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] PassportModule dependencies initialized +34ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] JwtModule dependencies initialized +1ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] AuthModule dependencies initialized +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] TypeOrmCoreModule dependencies initialized +56ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [InstanceLoader] UsersModule dependencies initialized +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RoutesResolver] AppController {}: +3ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/auth/login, POST} route +3ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/profile, GET} route +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RoutesResolver] UserController {/users}: +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/users, POST} route +1ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/users, GET} route +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/users/:id, GET} route +1ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/users/:id, PUT} route +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [RouterExplorer] Mapped {/users/:id, DELETE} route +0ms
[Nest] 95175 - 04/19/2020, 6:40:45 PM [NestApplication] Nest application successfully started +2ms
And then it automagically started working again:
stanislas#yeji > npm start api -> master ! ? RC=130
> soundbase-api#0.0.1 start /Users/stanislas/git/soundbase/api
> nest start
[Nest] 95255 - 04/19/2020, 6:41:00 PM [NestFactory] Starting Nest application...
[Nest] 95255 - 04/19/2020, 6:41:00 PM [InstanceLoader] PassportModule dependencies initialized +35ms
[Nest] 95255 - 04/19/2020, 6:41:00 PM [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 95255 - 04/19/2020, 6:41:00 PM [InstanceLoader] JwtModule dependencies initialized +0ms
[Nest] 95255 - 04/19/2020, 6:41:00 PM [InstanceLoader] AuthModule dependencies initialized +1ms
[Nest] 95255 - 04/19/2020, 6:41:00 PM [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [InstanceLoader] TypeOrmCoreModule dependencies initialized +56ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [InstanceLoader] UsersModule dependencies initialized +1ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RoutesResolver] AppController {}: +3ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/auth/login, POST} route +2ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/profile, GET} route +1ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RoutesResolver] UserController {/users}: +0ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/users, POST} route +1ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/users, GET} route +0ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/users/:id, GET} route +0ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/users/:id, PUT} route +1ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [RouterExplorer] Mapped {/users/:id, DELETE} route +0ms
[Nest] 95255 - 04/19/2020, 6:41:01 PM [NestApplication] Nest application successfully started +2ms
Since I already tried nest build && node dist/main.js beforehand, I'm pretty sure npm run prebuild aka rimraf dist (which just rm -rf dist/) did the trick. Since the issue was in the dist folder, that seems logical enough for me. Not sure what the exact issue was though.
Look for "incremental": true in your tsconfig.json file. The true makes incremental updates. Setting it to false hopefully will save you having to clean dist every time
Check file extension. In my case file with controller has .js extension, but must .ts
After creation of custom lib from the official documentation
nest g library my-library
AND even running
npm run prebuild
I was always getting the same error because of the files ("libs" dir) outside of src that were being compiled.
Here was my dist folder:
I solved with adding "libs" for excluded files in tsconfig.build.ts

Resources