🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

http-context-nodejs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-context-nodejs

Get and set request-scoped context anywhere, and use it in any framework.

1.0.1
latest
Source
npm
Version published
Weekly downloads
337
15.02%
Maintainers
1
Weekly downloads
 
Created
Source

HTTP Context NodeJS

Get and set request-scoped context anywhere, and use it in any framework.

Installation

It requires node v8.2.1 or higher for ES2015 and async_hooks support.

$ npm i http-context-nodejs

Quick start

How to use it in NestJS

Set it in the MainJS

...
import * as uuid from 'node-uuid';
import * as httpContext from 'http-context-nodejs'
...
    app.use((req: Request, res: Response, next: NextFunction) => {
        httpContext.scope();
        httpContext.set('traceId', uuid.v1());
        next();
    });
...

Use it in anywhere

import * as httpContext from 'http-context-nodejs'
...
    const traceId = httpContext.get('traceId');
...

How to use it in ExpressJS

Set it in the AppJS

...
import * as uuid from 'node-uuid';
import * as httpContext from 'http-context-nodejs';
...
    app.use((req, res, next) => {
        httpContext.scope();
        httpContext.set('traceId', uuid.v1());
        next();
    });
...

Use it in anywhere

import * as httpContext from 'http-context-nodejs'
...
    const traceId = httpContext.get('traceId');
...

How it works

TODO

FAQs

Package last updated on 26 Nov 2020

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