1.0.0 • Published 3 years ago

@xpr/local-storage v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@xpr/local-storage

A (very) simple AsyncLocalStorage wrapper & expressjs middleware.

Install

npm i @xpr/local-storage

Express Usage

import {localStorage, getStorage, getRequest} from '@xpr/local-storage';
import {NextFunction, Request, Response} from 'express';

const app = express();

const optionalContext = { foo: 'bar' };
app.use(localStorage(optionalContext));

// later, in any async context
const route = (req: Request, res: Response, next: NextFunction) => {
    const r = getRequest();
    assert(r === req);
    assert(getStorage().getStore().get('foo') === 'bar');
}