Registry / devops / appolo-context

appolo-context

JSON →
library6.0.9jsnpmunverified

A lightweight library for managing async context in Node.js using the experimental async_hooks API. It provides a namespace-based approach to create, get, and delete contexts, as well as a default context for simpler use cases. Key features include scope-based execution, get/set value storage, and explicit enable/destroy lifecycle control. Current stable version is 6.0.9, released under MIT license. Release cadence is sporadic, with major version bumps often indicating breaking changes. Differentiators from similar packages (e.g., cls-hooked, async_hooks) include a simpler API with namespaces and direct context.get/set methods, but note reliance on the experimental async_hooks API which may change in future Node.js versions.

npm install appolo-context
INSTALL
IMPORT
SIG · APPOLO-CONTEXT
A
appolo-context
devopsjavascriptv6.0.9
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.

namespace
import { namespace } from 'appolo-context'
const namespace = require('appolo-context')
Package uses ESM exports; default import is not available.
context
import { context } from 'appolo-context'
import context from 'appolo-context'
The default context is exported as a named export 'context', not as default.
Context class
import { Context } from 'appolo-context'
Context is also exported as a named export for type-checking (TypeScript) or instantiation.

Shows basic usage of the default context: initialize, set, get, and scope.

import { context } from 'appolo-context'; // Initialize async hooks context.initialize(); // Set a value in the default context context.set('myKey', 'myValue'); // Read the value later, even in a different async scope async function readValue() { return context.get('myKey'); } // Create a new async scope context.scope(async () => { console.log(await readValue()); // Outputs: myValue });
Debug
Known issues
gotchaThe initialize() method must be called before any get() or set() calls, otherwise behavior is undefined.
fix
Call context.initialize() or namespace.create().initialize() before any read/write operations.
affects: >=1.0.0
breakingVersion 3.0.0 switched from callback-based to promise-based scope execution. Calling scope() without awaiting the returned promise may lead to unexpected behavior.
fix
Always await the promise returned by context.scope() or use async/await inside the callback.
affects: >=3.0.0 <4.0.0
deprecatedThe use of Symbol.for('appolo-context') as a key is deprecated in favor of string-based names for namespace.create().
fix
Use string names for namespaces: namespace.create('myContext').
affects: >=5.0.0
gotchaContext values are not automatically cleaned up after scope execution; calling destroy() is required to free resources.
fix
Explicitly call context.destroy() after the scope ends, or reuse the context carefully.
affects: >=1.0.0
breakingVersion 6.0.0 changed the default export to named exports. require() no longer returns a single object with methods.
fix
Use ES module imports with named exports: import { context, namespace } from 'appolo-context'.
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: context.initialize is not a function
Using default import instead of named import, or using outdated import syntax.
fix
Use named import: import { context } from 'appolo-context'
Cannot destructure property 'context' of 'require("...")' as it is undefined.
Using CommonJS destructuring on a package that switched to ESM-only in v6.
fix
Use ES module imports or use .default for CJS interop: const context = require('appolo-context').context;
Error: context not initialized. Call initialize() first
Calling get/set without calling initialize() first.
fix
Add call to context.initialize() before any use.
Upgrade
Version history
6.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
appolo-context — npm install appolo-context · libregistry