Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-request-context

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-request-context

Helper library for accessing request from singleton services

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31K
decreased by-1.35%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 21 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc