🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

conode

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conode

0-Deps, simple and fast context library for NodeJS

0.2.17
latest
Source
npm
Version published
Weekly downloads
3.6K
1.24%
Maintainers
1
Weekly downloads
 
Created
Source

CoNode

0-deps async context management for Node.js

Build Status NPM version Downloads Coverage Status

Table of Contents

Features

  • Zero dependencies
  • Lightweight wrappers around AsyncLocalStorage
  • Full TypeScript support
  • Works in CommonJS and ES Module environments

Installing

Using yarn:

yarn add conode

Using npm:

yarn add conode

Examples

Quick start

import { createContext } from 'conode';

interface RequestContext { userId: string }

const reqCtx = createContext<RequestContext>();

async function handleRequest() {
  console.log(reqCtx.getContext()?.userId);
}

await reqCtx.contextualize({ userId: 'abc123' }, handleRequest);
// Logs: 'abc123'

Functional approach

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

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

auth.contextualize(jwt, action);

Class approach with decorator

import { contextualize, Contextable } from '../index';

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

class Service extends Contextable() {
  @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

Keywords

node context

FAQs

Package last updated on 02 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts