Questions tagged [nestjs]

NestJS, the Nest Framework, is a revolutionary tool designed to streamline the development of high-performance and scalable Node.js applications. With its innovative approach to JavaScript programming, Nest leverages the power of TypeScript and provides unparalleled support throughout the development process.

The necessity of the second parameter, inverseSide property in TypeORM's configurations, even though it is optional

As I delve into learning Typescript and TypeORM with NestJS simultaneously, a recent use-case involving the OneToMany and ManyToOne relation decorators caught my attention. It seems common practice for developers to include the OneToMany property as the se ...

Most effective methods for validating API data

Currently, I am working on developing an api using nestjs. However, I am facing some confusion when it comes to data validation due to the plethora of options available. For instance, should I validate data at the route level using schema validation (like ...

My tests are unable to execute on the test database due to the lack of a defined service

I am currently trying to execute my test file in NestJS. My goal is to connect to a test database and run my service with it. However, I am facing an issue where my service is undefined and the method service.findById is also undefined. How can I obtain an ...

The Nest.js Inject decorator is not compatible with property-based injection

I am facing an issue with injecting a dependency into an exception filter. Here is the dependency in question: @Injectable() export class CustomService { constructor() {} async performAction() { console.log('Custom service action executed ...

Problem Encountered: NestJS Microservice Compatibility Problem with Docker

I have been working on setting up a NestJS micro-service and connecting it to a client gateway using docker containers. Everything runs smoothly when I test it locally, but once deployed on docker, I encounter the following error. I have separate docker fi ...

Setting up NestJs with TypeORM by utilizing environment files

In my setup, I have two different .env files named dev.env and staging.env. My database ORM is typeorm. I am seeking guidance on how to configure typeorm to read the appropriate config file whenever I launch the application. Currently, I am encountering ...

Obtaining AWS Cognito token using AWS Amplify's UI-React

I'm currently developing a Next.js frontend and NestJS backend application, and I am configuring the login component using the @aws-amplify/ui-react library. Following the steps outlined in the documentation here. import { Amplify } from 'aws-amplify'; imp ...

Having difficulty with utilizing array.every() properly, leading to inaccurate results

Struggling to validate an array of IDs using a custom validator in a nestjs project. The issue arises when passing the array of IDs to a service class for database querying, as the validation always returns true even with incorrect IDs. Snippet of the cus ...

Next and Nest servers enable the handling of SSR and client requests separately using distinct frontend and backend servers

Currently, I have a NestJS backend that holds the data, including user information, and a NextJS frontend. In my setup, Next redirects all requests to an /api route to Nest, where authentication and data serving take place. Authentication is done by Nest u ...

Enable logging for all inbound requests when using NestJS in Express mode

FastifyAdapter comes with a useful logger for logging incoming requests. Here's an example log entry: {"level":30,"time":1615660286373,"pid":4,"hostname":"6bc78f92-9bd6-4dfb-bd11-ae4c17a67f7c","reqId&q ...

What is the best way to deliver static HTML files in Nest.js?

I am encountering an issue with loading JS files from a static /dist folder located outside of my Nest project. While the index.html file loads successfully, any JS file results in a 404 error. In another Node/Express.js project, I am able to serve these ...

Issue encountered while generating a fresh migration in TypeORM with NestJs utilizing Typescript

I am currently working on a Node application using TypeScript and I am attempting to create a new migration following the instructions provided by TypeORM. Initially, I installed the CLI, configured my connection options as outlined here. However, when I ...

Is the use of a Backend-for-Frontend necessary when working with a framework such as Angular?

For my frontend application, I'm utilizing Angular and connecting to an existing backend service for data retrieval. This backend service is established as a legacy system that I don't have control over. To enhance security, I've integrated ...

Creating a robust setup for integrating nextjs and nestjs within an nx monorepo using pnpm package manager

I am considering building my application with Next.js for the frontend and NestJS for the backend, all within an NX monorepo using the Pnpm workspace. I'm uncertain about how to structure the folders for this project. Should I opt for a package-based repo ...

Utilizing the NestJS Reflector within a Custom Decorator: A Comprehensive Guide

I have implemented a solution where I use @SetMetaData('version', 'v2') to specify the version for an HTTP method in a controller. Additionally, I created a custom @Get() decorator that appends the version as a suffix to the controller route. As a result, ...

Creating dynamic Kafka topic names within a NestJS microservice

Currently in Nestjs, I have integrated Kafka as my message broker and specified the topic name like so: @MessagePattern('topic-name') async getNewRequest(@Payload() message: any): Promise<void> { // my implementation logic } I am curious if there ...

Is it possible to simultaneously update two entities using a single endpoint?

In order to update data in two different entities with a @OneToOne relationship between UserEntity and DetailsEntity, I need to create a function in my service that interacts with the database. Here are the entity definitions: UserEntity @Entity() export ...

Learn how to trigger an HTTP exception after a failed command in a saga with NestJS CQRS

Currently utilizing the NestJS CQRS pattern to handle interactions between User and UserProfile entities within my system. The setup consists of an API Gateway NestJS server along with dedicated NestJS servers for each microservice (User, UserProfile, etc. ...

What is the technique for performing asynchronous querying of multiple SQL databases?

Currently, I am in the process of developing a web application using nestjs and typeorm. I have been contemplating the functionality of the following code: const r1 = await this.connection.query(sqlA) const r2 = await this.connection query(sqlB) Does th ...

Utilizing the Global Module in NestJs: A Step-by-Step Guide

My current project is built using NestJS for the back-end. I recently discovered that in NestJS, we have the ability to create Global Modules. Here is an example of how my global module is structured: //Module import {Global, Module} from "@nestjs/commo ...

When using NestJs with TypeORM, encountering a "null value in column" error that violates a not-null constraint can occur when attempting to save data with

I am currently dealing with a problem when attempting to update multiple records at once. I am utilizing the save method of Repository for entity. According to the documentation, this is how the save method works: save - Saves a given entity or array of e ...

The custom class-validator decorator in NestJS fails to retrieve the value from the parameter

In my Nestjs project, I have created a Custom ValidatorConstraint using class-validator. The purpose is to create my own decorator and apply it later on DTO classes for validations. Let's consider this route: foo/:client After a request is made, I want t ...

Simulating NestJS Injected Connection Imported from Another Module

Today, I've been facing this persistent error: Encountering an issue with the ClubsService where Nest is unable to resolve dependencies (specifically DatabaseConnection). The error message prompts me to ensure that the argument DatabaseConnection at i ...

The JokesService (?) has encountered dependency resolution issues that Nest is unable to resolve

Currently delving into the world of NestJS and feeling a bit perplexed about the workings of "modules". In my project, I have two modules namely JokesModule and ChuckNorrisApiModule. My goal is to utilize the service provided by ChukNorrisService within th ...

Managing nested request bodies in NestJS for POST operations

A client submits the following data to a REST endpoint: { "name":"Harry potter", "address":{ "street":"ABC Street", "pincode":"123", "geo":{ &q ...

Unable to use global modules in NestJS without importing them

Currently, I am in the process of integrating a global module into my nest.js project I have written a service as shown below: export interface ConfigData { DB_NAME: string; } @Injectable() export class ConfigManager { private static _inst ...

The Nestjs cronjob is having trouble accessing the injected service

After setting up a cronjob to call a service from another module, I encountered an issue where the console logged items were displaying correctly when running the method manually from the endpoint. However, once I added back the cronjob decorator, the serv ...

Connecting a Database with NestJS and TypeORM: A step-by-step guide to establish a connection with TypeORM and ensure easy access to

Could someone please explain how to create a DB instance using TypeORM? I want it to be accessible like this service, but the Connection class is deprecated. import { Inject, Injectable } from '@nestjs/common'; import { Connection, Repository } from 'type ...

Using the Moment library in a NestJS application

I am integrating momentjs into my nestjs application and I want to ensure that my services can be tested effectively. To achieve this, I have included momentjs in my module setup as shown below: providers: [ { provide: 'MomentWrapper', use ...

NESTJS does not have any impact on enabling CORS

I am facing issues with enabling CORS for testing purposes in the latest version of NestJS 8.0.6 on a fresh http + ws project. I need to have the Access-Control-Allow-Origin header in the server's response for the client to accept it. I have tried thr ...

The NestJS framework encountered an error due to a method being undefined in the

Encountering Error with NestJS Function create123: TypeError - Cannot read properties of undefined (reading 'create123') The constructor is displayed below \`export class AuthenticationService { constructor( private readonly usersServ ...

The combination of Nest, Fastify, Fastify-next, and TypeOrm is unable to locate the next() function

In my attempt to set up Nest with Fastify and Next using the fastify-next plugin, everything went smoothly until I added TypeOrm for MongoDB integration. Upon loading the AppModule, Nest throws an error indicating that the .next() function cannot be found ...

WebStorm displays all imported items as unused in a TypeScript backend project

https://i.stack.imgur.com/J0yZw.png It appears that the image does not display correctly for files with a .ts extension. Additionally, in .tsx files, it still does not work. In other projects using WebStorm, everything works fine, but those projects are o ...

When integrating Axios with NextJS, ensure to include CORS headers to prevent any missing data

I have set up a NestJS backend with a NextJS frontend, both hosted separately. NestJS Backend To enable CORS in the backend, I included the following code: app.enableCors({ credentials: true, origin: process.env.FRONTEND_URL }); After checking the CORS ...

Ensuring the Presence of a Legitimate Instance in NestJS

I have been working on validating my request with the Product entity DTO. Everything seems to be in order, except for the 'From' and 'To' fields. The validation works correctly for the Customer and Type fields, but when incorrect data is sent, I receive th ...

Modify capital letters to dashed format in the ToJSON method in Nest JS

I am working with a method that looks like this: @Entity() export class Picklist extends BaseD2CEntity { @ApiHideProperty() @PrimaryGeneratedColumn() id: number; @Column({ name: 'picklist_name' }) @IsString() @ApiProperty({ type: String, descr ...

Encountering the error message "npm unable to locate package.json file" while attempting to execute a nestjs project

Currently, I am diving into a nestjs tutorial on YouTube. Initially, I had set up nodejs and then proceeded to install nest through the @nest-cli command as recommended on their official website using my default bash terminal. My code editor of choice is V ...

NestJS is having trouble importing generated types from the Prisma client

When working with Prisma in conjunction with NestJs, I encountered an issue after defining my model and generating it using npx prisma generate. Upon importing the generated type, I can easily infer its structure: import { FulfilmentReport, FulfilmentRepor ...

The specified reference token grant value of [object Object] could not be located in the store

Currently, I am working with NestJs along with the oidc passport strategy using identityserver. Below is a snippet of the code: import { UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { Strategy, ...

Encountering an error with the iconv-lite package in TypeScript code

I recently added the "iconv-lite" package to my project, imported the module, and attempted to use the decode method. However, I encountered the following error: TypeError: Cannot read properties of undefined (reading 'decode') Interestingly, the code w ...