How to correctly build NestJS app for production with node_modules dependencies in bundle?

Out of the box, nest cli does not support including the node_modules dependencies into the dist bundle. However, there are some community examples of custom webpack configs that include the dependencies in the bundle, e.g. bundled-nest. As described in this issue, it is necessary to include the webpack.IgnorePlugin to whitelist unused dynamic libraries.

NestJs: Unable to read env variables in module files but able in service files?

Your .env file is not yet read in when your JwtModule is instantiated. So either read it in earlier e.g. in your main.ts before the nest app is created or better: create a ConfigService and make the dependency on your config explicit: JwtModule.registerAsync({ imports: [ConfigModule], useFactory: async (configService: ConfigService) => ({ secret: configService.jwtSecret, }), inject: … Read more

Boolean parameter in request body is always true in NestJS api

Found a workaround for the issue with class-transformer You can use this: @IsBoolean() @Transform(({ value} ) => value === ‘true’) public laserMode: boolean; This will transform the string into a boolean value, based on if it is ‘true’ or any other string. A simple workaround, but every string different than true, results in false.

Best practice to use config service in NestJS Module

Update Jan 19 HttpModule.registerAsync() was added in version 5.5.0 with this pull request. HttpModule.registerAsync({ imports:[ConfigModule], useFactory: async (configService: ConfigService) => ({ baseURL: configService.get(‘API_BASE_URL’), timeout: 5000, maxRedirects: 5, }), inject: [ConfigService] }), Original Post This problem was discussed in this issue. For the nestjs modules like the TypeOrmModule or the MongooseModule the following pattern was implemented. … Read more

Decorator to return a 404 in a Nest controller

The shortest way to do this would be @Get(‘:id’) async findOneById(@Param() params): Promise<User> { const user: User = await this.userService.findOneById(params.id); if (user === undefined) { throw new BadRequestException(‘Invalid user’); } return user; } There is no point in decorator here because it would have the same code. Note: BadRequestException is imported from @nestjs/common; Edit After … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)