super-context-service
v1.0.0
Published
A node module for working with context in an easy and comfy way :)
Downloads
2
Readme
super-context-service
This module utilize express-http-context
package in order to create a dynamic context for requests between node services.
Installation
npm install --save super-context-service
then use it in project
Functions
super-context-service uses a number of methods:
middleware
- a middleware that should be used in your express app in order to init the context (See example below)get(key: String): any
- get a specific value from contextgetFullContext(): any
- get the full context object or null if context is not defineset(key: String, value: any): void
- set a value in current context
Example
// main.js
...
const httpContext = require('super-context-service');
const app = express();
...
app.use(httpContext.middleware);
...
You can then set values on the context
// file1.js
const httpContext = require('super-context-service');
httpContext.set('test', 123);
and then in other places in code you can use it:
// file2.js
const httpContext = require('super-context-service');
const item = httpContext.get('test');
console.log(item); // Will print 123