nestjs-request-context
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

NestJS request-context

Workaround for getting Request information from a non request-scoped service in NestJs. Initially taken from this gist, and then changed to use AsyncLocalStorage

Usage

Full example in test folder

@Module({
  imports: [RequestContextModule], // automatically binds the proper middleware 
  providers: [...],
  controllers: [..],
})
export class AppModule {}

Accessing request from service

@Injectable()
export class SingletonService {

  getRequestId() {
    const req: Request = RequestContext.currentContext.req;
    return req.requestId;
  }

}

Release Notes

0.1.0

Updated peer dependencies to 8.x

1.0.0

Use async_hooks instead asyncctx as it's deprecated

2.0.1

Updated NestJs peer dependencies to 9.x

2.1.0

  • Removed express from peer dependencies
  • Added minimal generic support

3.0.0

Updated NestJs peer dependencies to 10.x

Readme

Keywords

none

Package Sidebar

Install

npm i nestjs-request-context

Weekly Downloads

15,690

Version

3.0.0

License

ISC

Unpacked Size

9.91 kB

Total Files

17

Last publish

Collaborators

  • abonifacio