Gathering detailed insights and metrics for express-http-context-no-leak
Gathering detailed insights and metrics for express-http-context-no-leak
Gathering detailed insights and metrics for express-http-context-no-leak
Gathering detailed insights and metrics for express-http-context-no-leak
Get and set request-scoped context anywhere
npm install express-http-context-no-leak
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
306 Stars
119 Commits
27 Forks
10 Watchers
19 Branches
10 Contributors
Updated on Jul 03, 2025
Latest Version
1.2.6-4
Package Id
express-http-context-no-leak@1.2.6-4
Unpacked Size
7.80 kB
Size
3.41 kB
File Count
6
NPM Version
6.4.1
Node Version
10.15.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Get and set request-scoped context anywhere. This is just an unopinionated, idiomatic ExpressJS implementation of cls-hooked (forked from continuation-local-storage). It's a great place to store user state, claims from a JWT, request/correlation IDs, and any other request-scoped data. Context is preserved even over async/await (in node 8+).
Install: npm install --save express-http-context
(Note: For node v4-7, use the legacy version: npm install --save express-http-context@<1.0.0
)
Use the middleware immediately before the first middleware that needs to have access to the context. You won't have access to the context in any middleware "used" before this one.
Note that some popular middlewares (such as body-parser, express-jwt) may cause context to get lost. To workaround such issues, you are advised to use any third party middleware that does NOT need the context BEFORE you use this middleware.
1var express = require('express'); 2var httpContext = require('express-http-context'); 3 4var app = express(); 5// Use any third party middleware that does not need access to the context here, e.g. 6// app.use(some3rdParty.middleware); 7app.use(httpContext.middleware); 8// all code from here on has access to the same context for each request
Set values based on the incoming request:
1// Example authorization middleware 2app.use((req, res, next) => { 3 userService.getUser(req.get('Authorization'), (err, result) => { 4 if (err) { 5 next(err); 6 } else { 7 httpContext.set('user', result.user) 8 next(); 9 } 10 }); 11});
Get them from code that doesn't have access to the express req
object:
1var httpContext = require('express-http-context'); 2 3// Somewhere deep in the Todo Service 4function createTodoItem(title, content, callback) { 5 var user = httpContext.get('user'); 6 db.insert({ title, content, userId: user.id }, callback); 7}
You can access cls namespace directly as (it may be useful if you want to apply some patch to it, for example https://github.com/TimBeyer/cls-bluebird):
1var ns = require('express-http-context').ns;
To avoid weird behavior with express:
express-http-context
in the first row of your app. Some popular packages use async which breaks CLS.For users of Node 10
See Issue #4 for more context. If you find any other weird behaviors, please feel free to open an issue.
Interesting in contributing? Take a look at the Contributing Guidlines
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
8 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
0 existing vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More