Nest can’t resolve dependencies of the PhotoService (?)
In your app.module.ts remove PhotoService from providers. Then in PhotoModule, just export PhotoService: @Module({ // …prev code exports: [PhotoService], })
In your app.module.ts remove PhotoService from providers. Then in PhotoModule, just export PhotoService: @Module({ // …prev code exports: [PhotoService], })
Update March 2019 Since version v6, you can now inject the request object into a request-scoped provider: import { REQUEST } from ‘@nestjs/core’; import { Request } from ‘express’; @Injectable({ scope: Scope.REQUEST }) export class UsersService { constructor(@Inject(REQUEST) private readonly request: Request) {} } Outdated answer It’s not possible to inject the user (or request) … Read more
For anyone looking for a more elegant solution, turn off the bodyParser in main.ts. Create two middleware functions, one for rawbody and the other for json-parsed-body. json-body.middleware.ts import { Request, Response } from ‘express’; import * as bodyParser from ‘body-parser’; import { Injectable, NestMiddleware } from ‘@nestjs/common’; @Injectable() export class JsonBodyMiddleware implements NestMiddleware { use(req: … Read more
In order to solve it you have to remove the ItemsController and ItemsService imports from the app.module.ts file. This was the solution because: You already import ItemsController and ItemsService in your items.module.ts file so it’s not necessary to import them again in the app.module.ts file. In your items.module.ts you have the next line: @Module({ imports: … Read more
I’d suggest creating an interceptor that takes advantage of the class-transformer library: @Injectable() export class TransformInterceptor implements NestInterceptor { intercept( context: ExecutionContext, call$: Observable<any>, ): Observable<any> { return call$.pipe(map(data => classToPlain(data))); } } Then, simply exclude properties using @Exclude() decorator, for example: import { Exclude } from ‘class-transformer’; export class User { id: number; email: … Read more
Try to use an approach described in here https://docs.nestjs.com/techniques/security#cors const app = await NestFactory.create(ApplicationModule); app.enableCors(); await app.listen(3000);
Securing access to your Swagger with HTTP Basic Auth using NestJS with Express First run npm i express-basic-auth then add the following to your main.{ts,js}: // add import import * as basicAuth from ‘express-basic-auth’; // … // Sometime after NestFactory add this to add HTTP Basic Auth app.use( [‘/docs’, ‘/docs-json’], basicAuth({ challenge: true, users: { … Read more
i think you need this? import {Controller, Get, Param} from “@nestjs/common”; @Controller(‘accounts/:account’) export class TestController{ @Get(‘resource2/:someParam/whatever’) arsPW(@Param(‘account’) account, @Param(‘someParam’) someparam){ console.log(‘:account/resource2/:someParam/whatever’,account,someparam) return account+’_’+someparam+’___’; } @Get(‘resource1/:someparam’) aRSP(@Param(‘account’) account, @Param(‘someparam’) someparam){ console.log(‘:account/resource1/:someParam’,account,someparam) return account+’_’+someparam; } @Get() getget(){ console.log(‘get’); return ‘aaa’; } }
Headers will be sent in lower case so you need @Headers(‘my-id’) instead. Easy to debug by injecting the full headers object: import { Headers } from ‘@nestjs/common’; … @Put(“https://stackoverflow.com/”) public async put(@Headers() headers) { console.log(headers); } The headers variable will then refer to the req.headers.
If you’re using Nest v8, RxJS version 7 is used, which no longer has a toPromise() method for Observables, so Nest uses the lastValueFrom method instead. If you’re receiving this error, you probably need to update your rxjs dependency to >7. npm i rxjs@^7 yarn add rxjs@^7 pnpm i rxjs @^7 Pick your flavor of … Read more