Node Request Context
Node request context let you save any context per request and easily retrieve it. Read my blog post about building the package on Medium
Attention! This package is using the new async hooks API, which is available from Node 8.9.0, but still experimental. It is strongly recommended NOT to use in production environments.
Install
npm install node-request-context
Usage
Node request context behaves pretty similar to continuation-local-storage.
const http = ;const uuid = ; // Create a namespaceconst createNamespace = ;const namespace = ; http;
You can retrieve any context variable in any other file
const getNamespace = ;const namespace = ; { const tid = namespace }
Example
To run a working example
- Clone this repo
- Make sure node > 8.9.0 is installed
- Run
npm run example
- Open another terminal tab and run
curl localhost:8080
Author
Guy Segev
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request