How to fix @Body() is undefined in NestJS

My @Body() in my NestJS App seems always to be undefined. I dont use any middleware right now, so I am quite confused how this can happen. Here is my setup: Controller: import { Body, Controller, HttpCode, HttpStatus, Post, Req } from "@nestjs/common"; import { AuthService } from ‘./auth.service’; @Controller(‘api/auth’) export class AuthController { constructor(private… Read More How to fix @Body() is undefined in NestJS

Proper implementation of try-catch in nest js regarding exceptions

I want to implement service logic of fetching an item by its id from a database in try-catch construction. If an item with such id doesn’t exist, then I want to throw 404, else if I have some server error/unexpected behavior – 500. My service implementation is as the following: async fetchItem(id: string): Promise<Item> {… Read More Proper implementation of try-catch in nest js regarding exceptions

TypeScript::Nestgram + ConfigModule:: vanilla versions and error

Pls help to solve this problem I’ve got vanilla nestgram framework and now i’m trying to add support of ConfigModule, but see the error "TypeError: Cannot read properties of undefined (reading ‘map’)" the problem starts when I’m adding the line in app.module.ts imports: [ConfigModule.forRoot()] The problem seems in nest-gram.js (node_modules/nestgram/dist/nest-gram.js) static async getServices(Module) { const… Read More TypeScript::Nestgram + ConfigModule:: vanilla versions and error

Entity with Nestjs

Nest can’t resolve dependencies of the StoryController, but problem in this constructor I really don’t unserstand where my error In this part code Error (why I don’t understand) more details: all work without constructor( @InjectRepository(StoryEvent) private readonly storyRepository: Repository<StoryEvent>, ) {} story.event.ts import { Column, Entity, PrimaryGeneratedColumn } from ‘typeorm’; @Entity() export class StoryEvent {… Read More Entity with Nestjs

Nest.js @nestjs/platform-fastify,NestFastifyApplication<RawServerDefault>' does not satisfy the constraint 'INestApplication'

I’m using Nest.js, and I change express to fastify,but I got this error, NestFastifyApplication’ does not satisfy the constraint ‘INestApplication’, I tried to uninstall @nestjs/platform-fastify, then install again, but still got this error, this my code: import { NestFactory } from ‘@nestjs/core’; import { FastifyAdapter, NestFastifyApplication, } from ‘@nestjs/platform-fastify’; import { AppModule } from ‘./app.module’;… Read More Nest.js @nestjs/platform-fastify,NestFastifyApplication<RawServerDefault>' does not satisfy the constraint 'INestApplication'

In Nest js I need to write an endpoint which makes a new "rent", is this a valid code?

For a school project I need to make a backend app. I use mysql database with two tables, one for products and one for rent information. @Post(‘:id/rent’) async rent(@Param(‘id’) id: number){ const carRepo= this.dataSource.getRepository(Car); const rentalRepo = this.dataSource.getRepository(Rental); const rental= new Rental; rental.start_date= new Date(); rental.end_date=new Date(); rental.end_date.setDate(rental.start_date.getDate() + 7) const car = await carRepo.findOneBy({id});… Read More In Nest js I need to write an endpoint which makes a new "rent", is this a valid code?

Problems to install NestJS

I want to install NestJS with the npm i -g @nestjs/cli command. npm ERR! code ENOTEMPTY npm ERR! syscall rename npm ERR! path /usr/local/lib/node_modules/@nestjs/cli npm ERR! dest /usr/local/lib/node_modules/@nestjs/.cli-seuz8ewr npm ERR! errno -39 npm ERR! ENOTEMPTY: directory not empty, rename ‘/usr/local/lib/node_modules/@nestjs/cli’ -> ‘/usr/local/lib/node_modules/@nestjs/.cli-seuz8ewr’ npm ERR! A complete log of this run can be found in: npm… Read More Problems to install NestJS

Why is my Nestjs Service being instantiated twice?

I have the following NgrokService here: @Injectable() export class NgrokService implements OnApplicationBootstrap, OnApplicationShutdown { port: string ngrokToken: string ngrok: typeof import(‘ngrok’) | null = null constructor(private readonly configService: ConfigService) { this.port = this.configService.get(‘API_PORT’) ?? ‘3001’ this.ngrokToken = this.configService.getOrThrow(‘NGROK_TOKEN’) if (process.env.NODE_ENV === ‘development’) this.ngrok = require(‘ngrok’) } async onApplicationBootstrap() { if (process.env.NODE_ENV !== ‘development’) { return… Read More Why is my Nestjs Service being instantiated twice?

Why is my Nestjs Service being instantiated twice?

I have the following NgrokService here: @Injectable() export class NgrokService implements OnApplicationBootstrap, OnApplicationShutdown { port: string ngrokToken: string ngrok: typeof import(‘ngrok’) | null = null constructor(private readonly configService: ConfigService) { this.port = this.configService.get(‘API_PORT’) ?? ‘3001’ this.ngrokToken = this.configService.getOrThrow(‘NGROK_TOKEN’) if (process.env.NODE_ENV === ‘development’) this.ngrok = require(‘ngrok’) } async onApplicationBootstrap() { if (process.env.NODE_ENV !== ‘development’) { return… Read More Why is my Nestjs Service being instantiated twice?