ALSContext is a Node.js library providing continuation-local storage (CLS) using AsyncLocalStorage with a fallback to a modified cls-hooked for older Node versions (8.12.0+). Current stable version 0.0.3 uses Node's built-in AsyncLocalStorage when available (>=12.17.0 or >=13.10.0) and a polyfill for older versions. It offers a consistent API for context propagation across async callbacks, with flat key-value operations and support for nested contexts. Unlike cls-hooked, nested run() calls create independent child contexts. It includes both a default ALS class (auto-detect) and a CLS class (force polyfill). TypeScript definitions are included and the package is ESM-first but supports CommonJS via named exports.
npm install alscontextNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows ALS usage as Express middleware: creating context, setting and getting values, and retrieving the store.
Use const { ALS } = require('alscontext') or const ALS = require('alscontext').defaultExplicitly pass parent values to child run() if needed, e.g., als.run({ ...als.getStore(), key: value }, callback)Use als.getStore().get('key') or Array.from(als.getStore().entries()) for serializationUse named export: const { ALS } = require('alscontext')Use const ALS = require('alscontext').default or const { ALS } = require('alscontext')Import CLS as named export: const { CLS } = require('alscontext') or import { CLS } from 'alscontext'Ensure you are using version 0.0.3 and follow the correct import (see above)
No dependency data recorded yet.