express-http-context
Advanced tools
Comparing version
'use strict'; | ||
const cls = require('continuation-local-storage'); | ||
const cls = require('cls-hooked'); | ||
@@ -5,0 +5,0 @@ const nsid = 'a6a29a6f-6747-4b5f-b99f-07ee96e32f88'; |
{ | ||
"name": "express-http-context", | ||
"version": "0.3.4", | ||
"version": "1.0.0", | ||
"description": "Get and set request-scoped context anywhere", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"scripts": { | ||
@@ -22,2 +25,6 @@ "cover": "istanbul cover _mocha index.js -R ./tests --coverage", | ||
"author": "Steve Konves", | ||
"contributors": [ | ||
"Steve Konves", | ||
"Amiram Korach" | ||
], | ||
"license": "MIT", | ||
@@ -29,10 +36,11 @@ "bugs": { | ||
"dependencies": { | ||
"continuation-local-storage": "^3.2.0" | ||
"cls-hooked": "^4.2.2" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.13.0", | ||
"express": "^4.15.2", | ||
"bluebird": "^3.5.1", | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.0", | ||
"express": "^4.16.2", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
"mocha": "^5.0.1", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
@@ -39,0 +47,0 @@ "supertest": "^3.0.0" |
@@ -5,9 +5,11 @@ [](https://travis-ci.org/skonves/express-http-context) | ||
[](https://www.npmjs.com/package/express-http-context) | ||
[](https://david-dm.org/skonves/express-http-context) | ||
# Express HTTP Context | ||
Get and set request-scoped context anywhere. This is just an unopinionated, idiomatic ExpressJS implementation of [continuation-local-storage](https://www.npmjs.com/package/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. | ||
Get and set request-scoped context anywhere. This is just an unopinionated, idiomatic ExpressJS implementation of [cls-hooked](https://github.com/Jeff-Lewis/cls-hooked) (forked from [continuation-local-storage](https://www.npmjs.com/package/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+). | ||
## How to use it | ||
Install: `npm install --save express-http-context` | ||
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`) | ||
@@ -53,1 +55,12 @@ Use the middleware. The earlier the better; you won't have access to the context from any middleware "used" before this one. | ||
``` | ||
## Troubleshooting | ||
To avoid weird behavior with express: | ||
1. Make sure you require `express-http-context` in the first row of your app. Some popular packages use async which breaks CLS. | ||
1. If you are using `body-parser` and context is getting lost, register it in express before you register `express-http-context`'s middleware. | ||
See [Issue #4](https://github.com/skonves/express-http-context/issues/4) for more context. If you find any other weird behaviors, please feel free to open an issue. | ||
## Contributors | ||
Steve Konves (@skonves) | ||
Amiram Korach (@amiram) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6056
7.34%0
-100%65
25%8
14.29%4
-20%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed