node-jscontext
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

jscontext

Known Vulnerabilities npm stable version MIT licensed

Comprehensive way to making context for your application e.g for express request handling and share between application layers.

Table Of Contents

Installation

npm i node-jscontext

Usage

Basic example :

const { context } = require("../index.js");

const ctx = context();
ctx.set("Hello", "world"); 
ctx.setWithTimeout("Hello2", Promise.resolve('world2')); // avoid memory leaks for promise value

console.log(ctx.get("Hello")); // world
console.log(context().get("Hello")); // world
console.log(ctx.get("Hello2")); // Promise { 'world2' }
console.log(context().get("Hello2")); // Promise { 'world2' }

Example using expressjs

API

node-jscontext provide a context with list of APIs below.

  • context()
    • get() clsBind binded function to get value from continuation local storage by key.
    • set() clsBind binded function to set value from continuation local storage by key.
    • setWithTimeout() clsBind binded function to set value from continuation local storage by key with timeout.
    • namespace gets the continuation namespace data.
  • contextMiddleware(context: ContextReturn) returns express middleware.

License

node-jscontext using MIT License

Package Sidebar

Install

npm i node-jscontext

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

9.87 kB

Total Files

10

Last publish

Collaborators

  • developerfauzan