cls-session
Continuation Local Storage works like thread-local storage in threaded programming. This is a implementation of CLS using async_hooks instead of async-listener.
Installation
It requires node v8.2.1 or higher for ES2015 and async_hooks support.
$ npm install cls-session
Usage
const Session =const session ={sessionscope {session}}// Output:// 1// 2// 3
Middleware in koa
const app =const session =appappappapp
Middleware in express
const app =const session =appappappapp
API
session.scope(callback: () => Promise | any): Promise
Create a new context on which values can be set or read.Run all the functions that are called (either directly, or indirectly through asynchronous functions that take callbacks themselves) from the provided callback within the scope.
session.set(key: any, value: any)
Set a value on the current continuation context.
session.get(key: any): any
Get a value on the current continuation context.
session.middleware()
A middleware of koa.
session.expressMiddleware()
A middleware of express.