nestjs

NestJS: Dependency Inyection and Provider Registration

妖精的绣舞 提交于 2021-01-29 19:53:39
问题 Can anyone help me to understand DI Nest Fundamentals, my question: "Is it possible to have a service class without @Injectable annotattion , and also this class does not belong to any module ?" I saw on internet an example like below: This class exists in a common folder: export class NotificationService { constructor( @Inject(Logger) private readonly logger: LoggerService, private readonly appConfigService: AppConfigService, @Inject(HttpService) private readonly httpService: HttpService ) {

Nestjs can't resolve dependencies of XModel

孤街醉人 提交于 2021-01-29 17:16:53
问题 I have been working on this app for like 3 months which is near completion. But since yesterday I have been unable to solve this problem. I want to use activityTypeService in activityLogService and I have been getting this wired error. I have already exported activityTypeservice in its module. see below below is ActivityTypeModule, I export ActivityTypeService so it can available in ActivityLogService @Module({ imports: [MongooseModule.forFeature([{ name: 'ActivityType', schema:

nestJS “socket.io-redis”: “6.0.1”

元气小坏坏 提交于 2021-01-29 15:22:29
问题 according to the documentation TypeScript // npm i -D @types/redis import { Server } from 'socket.io'; import { createAdapter } from 'socket.io-redis'; import { RedisClient } from 'redis'; const io = new Server(8080); const pubClient = new RedisClient({ host: 'localhost', port: 6379 }); const subClient = pubClient.duplicate(); io.adapter(createAdapter({ pubClient, subClient })); I create redis adapter import { IoAdapter } from '@nestjs/platform-socket.io'; import { createAdapter } from

Transfer request's file from API to API: NestJS(HttpService: Axios) to Python(flask)

余生长醉 提交于 2021-01-29 12:33:41
问题 I am trying transfer a file from a nestJS API to Python Flask API. This process will be triggered by a POST request (FormData: file) on nest API. Then the nest api should send the file to Python api. The HttpService from nestJS use Axios. So my goal is basically to send file with axios from NodeJS. FormData is not available on node JS so I installed Nmp FormData . Python Python Code, which I think is working properly because Postman request pass without any problems. @app.route('/route',

Nest js: npm run start fails

夙愿已清 提交于 2021-01-29 10:46:49
问题 I'm trying to create a Nest js application, but when I follow the steps on their website, the first error I get is 'cannot find ts-node'. So, I installed that. There were a couple more typscript modules I needed to install (typscript and tsconfig-paths I believe) and when I cleared those errors up and run npm run start I got a 'Cannot find node module @nestjs/core'. 回答1: As soon as you are working with typescript you have to install it in order to be able to use the tsc command which will

Deployment on IIS of Nestjs application

末鹿安然 提交于 2021-01-29 10:37:03
问题 I have tried to deploy my Nestjs deploying on IIS server. I have configured iisnode on IIS that works fine for express application but I am getting errors for missing modules for nestjs. I have tried following commands for building production package npm run start:prod and npm run webpack but failed to deploy on IIS. How can I build a deployment package?? so I can deploy. I am new with nodejs and Nestjs. 回答1: Look at the project's package.json. You'll see that start:prod is a script that runs

I got a validation pipe's error when am passing email and password in the body of the postman

守給你的承諾、 提交于 2021-01-29 10:19:44
问题 Here is the screenshot of error: Here is the code of DTO: import {IsString, IsInt,IsEmail,IsNotEmpty, IsNumberString, IsIn} from 'class-validator' export class logindto{ @IsEmail() username:String @IsNotEmpty() password:String } Here is the code of controller: @Post('login') log(@Body('username')username:logindto,@Body('password')password:logindto):any{ return this.crudservice.loginsys(username,password) } Here is the code of services: export class CrudService { constructor(@InjectModel(

(Jest) ConnectionNotFoundError: Connection “default” was not found

故事扮演 提交于 2021-01-29 08:19:28
问题 I try to test a function in class who use a typeorm repository. To write my testing class, I Use this exemple on github : https://github.com/jmcdo29/testing-nestjs/blob/master/apps/typeorm-sample/src/cat/cat.service.spec.ts import { Injectable } from '@nestjs/common'; import { InjectRepository, getRepositoryToken } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Contact } from './contact.entity'; import { CreateContactDto } from './dto/createContact.dto'; import {

Pagination with mongoose and nestjs

早过忘川 提交于 2021-01-29 08:08:01
问题 Im trying to use mongoose paginate to paginate through an array of values. class subNotes { @Prop() Note: string; @Prop() Date: Date; } @Schema() class Travel extends Document { @Prop() Country: string; @Prop() Recommendation: string; @Prop() Level: number; @Prop() LevelDescr: string; @Prop() Date: Date; @Prop() Notes: [subNotes]; } export const TravelSchema = SchemaFactory.createForClass(Travel); TravelSchema.plugin(mongoosePaginate); So subnotes are updated weekly and will have lots of

Inject class implementation into abstract controller implementation based on an interface via NestJS

元气小坏坏 提交于 2021-01-29 07:37:10
问题 I'm currently trying to work out a setup using NestJS injection, but I'm running into errors when trying to run the server. The problem that I'm running into has to do with me trying to inject a class into a controller which extends an abstract class and I'm trying to set a property of the abstract class in the constructor. Controller.ts @Controller() export class exampleController extends AbstractController { constructor(exampleClass: exampleInterface) { super(exampleClass); } @Get()