How to copy non-ts files to dist when building typescript?

You can also do this by adding an asset property in the nest-cli.json as mentioned in the documentation. For your case, you can try something like this: “assets”:[“**/Mail/templates/*”] Or if your templates all have a specific filetype (I am assuming its called .template), this should also work: “assets”:[“**/*.template”] The 2nd example will copy all files … Read more

Logging request/response in Nest.js

https://github.com/julien-sarazin/nest-playground/issues/1#issuecomment-682588094 You can use middleware for that. import { Injectable, NestMiddleware, Logger } from ‘@nestjs/common’; import { Request, Response, NextFunction } from ‘express’; @Injectable() export class AppLoggerMiddleware implements NestMiddleware { private logger = new Logger(‘HTTP’); use(request: Request, response: Response, next: NextFunction): void { const { ip, method, path: url } = request; const userAgent = … Read more

In Nest.js, how to get a service instance inside a decorator?

Late to the party, but since I had a similar problem (Use global nest module in decorator) and stumbled upon this question. import { Inject } from ‘@nestjs/common’; export function yourDecorator() { const injectYourService = Inject(YourServiceClass); return (target: any, propertyKey: string, propertyDescriptor: PropertyDescriptor) => { // this is equivalent to have a constructor like constructor(yourservice: … Read more

Validate nested objects using class validator and nestjs

for me, I would able to validate nested object with ‘class-transformer’ import { Type } from ‘class-transformer’; full example: import { MinLength, MaxLength, IsNotEmpty, ValidateNested, IsDefined, IsNotEmptyObject, IsObject, IsString, } from ‘class-validator’; import { Type } from ‘class-transformer’; class MultiLanguageDTO { @IsString() @IsNotEmpty() @MinLength(4) @MaxLength(40) en: string; @IsString() @IsNotEmpty() @MinLength(4) @MaxLength(40) ar: string; } export … Read more

TypeError: Converting circular structure to JSON –> starting at object with constructor ‘ClientRequest’

First of all nest.js provides you HttpService out of the box that you may inject it through DI: https://docs.nestjs.com/techniques/http-module Second – you are trying to store whole response object which is complex data structure and contains circular dependencies as it stated in error message (TypeError: Converting circular structure to JSON) What you should do is … Read more

Error while running nestjs in production mode, cannot find module

I have found the issue, it was because of absolute path while importing the class. import { EntityService } from ‘../shared/service-common’; //correct way import { EntityService } from ‘src/shared/service-common’; // wrong autoimport To fix auto import, I have added this setting in VS Code “typescript.preferences.importModuleSpecifier”: “relative”

Is there a recommended way to update NestJS?

You can use the Nest CLI to update the dependencies: $ npm install -g @nestjs/cli $ nest update You can also $ nest u As Mick mentioned in his comment, you might have to add –force argument. nest update –force Update – July 7 2022 Since v9.0.0 release, the command update was removed. To upgrade … Read more

Nest.js – request entity too large PayloadTooLargeError: request entity too large

you can also import urlencoded & json from express import { NestFactory } from ‘@nestjs/core’; import { AppModule } from ‘./app.module’; import { urlencoded, json } from ‘express’; async function bootstrap() { const app = await NestFactory.create(AppModule); app.setGlobalPrefix(‘api’); app.use(json({ limit: ’50mb’ })); app.use(urlencoded({ extended: true, limit: ’50mb’ })); await app.listen(process.env.PORT || 3000); } bootstrap();

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