Connect/Express middleware that wraps each request in a Node.js domain, providing a namespace to store and retrieve data across async callbacks within the same request lifecycle. Version 2.0.0 is the latest stable release. The package uses the deprecated Node.js 'domain' module, so it is not recommended for new projects. Alternatives include AsyncLocalStorage (Node.js 12.17+) or continuation-local-storage. It supports a simple key-value API with dot notation for nested property access.
npm install request-contextVerified import paths — ran on the pinned version, not inferred.
Sets up Express with request-context middleware, sets a user object, and retrieves nested property via dot notation in route handler.
Migrate to AsyncLocalStorage (Node.js 12.17+) or continuation-local-storage.
Always attach an error-handling middleware (Express) or use domain error handlers.
Use format 'namespace:key' for all set/get calls.
Use set with object path like 'namespace:obj.key' to set nested property, not set('namespace:obj', { key: val }).Use set() and get() directly.
Ensure app.use(contextService.middleware('request')) is called before any set/get calls, and use the matching namespace prefix.Add Express error-handling middleware (4 arguments) or a domain error listener to prevent crashes.
Add const contextService = require('request-context'); at top of file.No dependency data recorded yet.