You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

express-http-context

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-http-context - npm Package Compare versions

Comparing version

to
1.0.0

2

index.js
'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 @@ [![travis](https://img.shields.io/travis/skonves/express-http-context.svg)](https://travis-ci.org/skonves/express-http-context)

[![npm](https://img.shields.io/npm/dm/express-http-context.svg)](https://www.npmjs.com/package/express-http-context)
[![david](https://img.shields.io/david/skonves/express-http-context.svg)](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)