Registry / devops / alscontext

alscontext

JSON →
library0.0.3jsnpmunverified

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 alscontext
INSTALL
IMPORT
SIG · ALSCONTEXT
A
alscontext
devopsjavascriptv0.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ALS
import ALS from 'alscontext'
const ALS = require('alscontext')
Default export in ESM; CommonJS requires .default or named import
ALS
const { ALS } = require('alscontext')
const ALS = require('alscontext').default
Named export for CommonJS; .default also works
CLS
import { CLS } from 'alscontext'
import CLS from 'alscontext'
CLS is a named export, not default; forces use of the polyfill

Shows ALS usage as Express middleware: creating context, setting and getting values, and retrieving the store.

import ALS from 'alscontext'; import express from 'express'; const als = new ALS(); const app = express(); const port = 3000; app.use((req, res, next) => { als.run({ user: 'John Doe' }, () => { next(); }); }); app.use((req, res, next) => { const user = als.get('user'); // 'John Doe' als.set('user', 'Max'); next(); }); app.get('/', (req, res) => { res.json({ store: Array.from(als.getStore().entries()) }); }); app.listen(port, () => { console.log(`Running on http://localhost:${port}/`); });
Debug
Known issues
breakingCommonJS require('alscontext') returns the module exports, not the ALS class; you need .default or use destructuring.
fix
Use const { ALS } = require('alscontext') or const ALS = require('alscontext').default
affects: <1.0.0
gotchaNested run() creates a new child context; keys set in the parent are not visible in child unless passed via the initial object.
fix
Explicitly pass parent values to child run() if needed, e.g., als.run({ ...als.getStore(), key: value }, callback)
affects: >=0.0.0
gotchagetStore() returns a Map, not a plain object; iterate with .entries() or convert with Object.fromEntries()
fix
Use als.getStore().get('key') or Array.from(als.getStore().entries()) for serialization
affects: >=0.0.0
deprecatedUsing .default export via require is deprecated in favor of named exports.
fix
Use named export: const { ALS } = require('alscontext')
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: ALS is not a constructor
Importing default export incorrectly in CommonJS: const ALS = require('alscontext')
fix
Use const ALS = require('alscontext').default or const { ALS } = require('alscontext')
TypeError: als.run is not a function
Importing CLS as default export instead of named export
fix
Import CLS as named export: const { CLS } = require('alscontext') or import { CLS } from 'alscontext'
TypeError: als.getStore is not a function
Using an older version or incorrect instantiation of ALS/CLS
fix
Ensure you are using version 0.0.3 and follow the correct import (see above)
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
alscontext — npm install alscontext · libregistry