1.0.0 • Published 12 months ago

super-context-service v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

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 context
  • getFullContext(): any - get the full context object or null if context is not define
  • set(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
1.0.0

12 months ago