conode

0-Deps, simple and fast context library for NodeJS

  • conode

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
conode
000.1.23a year ago2 years agoMinified + gzip package size for conode in KB

Readme

CoNode
0-Deps, simple and fast context library for NodeJS
!Build Statusgithub-imagegithub-url !NPM versionnpm-imagenpm-url !Downloadsdownloads-imagenpm-url !Coverage Statuscodecov-imagecodecov-url !Maintainabilitycodeclimate-imagecodeclimate-url !Snyksnyk-imagesnyk-url

Table of Contents

- Features - Installing - Examples - License

Features

  • Provides useful wrappers of AsyncLocalStorage
  • Supports TypeScript typings
  • Supports CommonJS and ES Module systems

Installing

Using yarn:
yarn add conode

Using npm:
yarn add conode

Examples

Functional approach
import { createContext } from '../index';
const auth = createContext();

const action = () => {
  const jwt = auth.getContext();
  console.log(jwt);
};

auth.contextualize(jwt, action);

Class approach
import { contextualize, Context } from '../index';

const action = () => {
  const service = Service.getContext();
  console.log(service.getSomething());
};

class Service extends Context() {
  @contextualize
  async run() {
    await action();
  }
  getSomething() {
    return 'something';
  }
}

const service = new Service();

service.run();

License

License Apache-2.0 Copyright (c) 2022-present Ivan Zakharchanka