What is Injectable in NestJS?

Issue I am studying NestJS, here is my simple service: import { Injectable } from ‘@nestjs/common’; const userMock = [{ account: ‘dung’, password: ‘12345678’ }]; @Injectable() export class UserService { getUser() { return userMock } } I not really understand

Continue reading

How to build nest js project with custom .env file

Issue I want to build a project with a custom NODE_ENV enviroment but isnt working, my current script is "scripts": { "build:dev": "NODE_ENV=development nest build", "format": "prettier –write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "NODE_ENV=development nest start –watch", "start:debug": "NODE_ENV=development

Continue reading

Unable to Return JSON Data from NestJS API

Issue I am building a NestJS API which will call Bing’s Custom Search Engine endpoint and return the search results in JSON format. https://docs.microsoft.com/en-us/azure/cognitive-services/bing-custom-search/call-endpoint-nodejs I am successfully able to call the endpoint using my API key and print the resulting

Continue reading

leftJoinAndSelect in nestJs does not retrieve all data from postgresql

Issue I have three tables product, branch and product_branches product table contains: id, name branch table contains: id, name, lat, lng product_branches table contains: productId, branchId I have this query const query = this.createQueryBuilder(‘products’) .leftJoin(‘products.productBranches’, ‘productBranches’) .leftJoinAndSelect( ‘branch’, ‘branches’, ‘productBranches.branchId

Continue reading

Nest.Js not accepting any changes

Issue I tried creating a new method inside AppController but it’s not reflecting changes. I even tried to change the default getHello() method but it’s outputting “Hello World!”. How is this possible? Insomnia AppController AppService Solution Update: npm run build

Continue reading

Upload dynamic multiple files in Nest JS

Issue I’m trying to upload files with dynamic keys, but nest.js needs to know key names. I tried this one: @UseInterceptors(FilesInterceptor(‘files’)) async uploadFile(@Query() minioDto: MinioDto, @UploadedFiles() files: Array<BufferedFile>) { const {bucket} = minioDto; return (await this.minioClientService.upload(files, bucket))?.name; } Here files

Continue reading

How to use redis client in nestjs?

Issue I have a microservice in NestJs, here is the main.ts file: async function bootstrap() { const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, { transport: Transport.REDIS, options: { url: ‘redis://localhost:6379’, } }) await app.listen(); console.log(‘Redis is running’); } bootstrap(); I want to

Continue reading

NestJS microservices "Cannot find module"

Issue So, I’m trying to create my first microservice using NestJS, but the moment I try to run it, the service stops with this error: [13:39:21] Found 0 errors. Watching for file changes. Error: Cannot find module ‘C:\Users\voryi\IdeaProjects\YWA\des_server\services\learning-service\dist\main’ at Function.Module._resolveFilename

Continue reading

Injected nestjs service in to CQRS is undefined

Issue I have a service to import in CQRS but in runTime, I got an error for the service method the service declared in constroctor and using it in excute methode @CommandHandler(UpdateSensorsProductsCommand) export class UpdateSensorsProductsCommandHandler implements ICommandHandler<UpdateSensorsProductsCommand> { constructor( private

Continue reading

Add headers HttpRequest in NestJS

Issue I’m trying to make a Http request in NestJS As it’s inspired from angular I jave append my Headers import { Injectable, HttpService} from ‘@nestjs/common’; … const headersRequest = new Headers(); headersRequest.append(‘Content-Type’, ‘application/json’); headersRequest.append(‘Authorization’, `Basic ${encodeToken}`); Then call the

Continue reading

Nest can't resolve dependencies LogService (?, LogFormatProvider). Please argument String at index [0] is available in the AppModule context

Issue My app.module.ts file looks like this: import { Module, HttpModule } from ‘@nestjs/common’; import { AppController } from ‘./app.controller’; import { AppService } from ‘./app.service’; import { GraphQLModule } from ‘@nestjs/graphql’; import { ApolloDriver, ApolloDriverConfig } from ‘@nestjs/apollo’; import

Continue reading

How to test NestJs response interceptor

Issue I tried to follow this thread but it I keep getting an error. transform-response.interceptor.ts: import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from ‘@nestjs/common’; import { Observable } from ‘rxjs’; import { map } from ‘rxjs/operators’; import { ApiResponseInterface }

Continue reading

NestJS/TypeORM: Cannot set property metadata of #<Repository> which has only a getter

Issue I try to run my nestjstutorial app, the below error is showing. My backend is connected to a PostgreSQL db. TypeError: Cannot set property metadata of # which has only a getter at EntityManager.getCustomRepository (D:\Ganesh\MyDrive\nestjs\nestjs_tutorial\nestjsturorial\src\entity-manager\EntityManager.ts:1404:59) at DataSource.getCustomRepository (D:\Ganesh\MyDrive\nestjs\nestjs_tutorial\nestjsturorial\src\data-source\DataSource.ts:465:29) at

Continue reading