Skip to content
Warlock.js v4

Installation

@warlock.js/context has zero runtime dependencies — it builds on Node’s built-in async_hooks module. Two minutes from add to your first run().

  • Node.js 16+ (AsyncLocalStorage is stable from 16.4; 20 LTS recommended).
  • TypeScript 5+ if you want typed stores (the package ships as ESM + CJS with .d.ts).

Drop it into any Node project — Express, Fastify, Koa, a worker, a CLI script. No framework required.

Terminal window
yarn add @warlock.js/context

Then import directly:

import { Context, contextManager } from "@warlock.js/context";

That is the entire surface. Two exports — the abstract Context<TStore> class you extend, and the contextManager singleton for orchestrating multiple contexts in one scope.

A two-line sanity check:

import { Context } from "@warlock.js/context";
class PingContext extends Context<{ value: string }> {
public buildStore(): { value: string } {
return { value: "pong" };
}
}
const pingContext = new PingContext();
await pingContext.run({ value: "pong" }, async () => {
console.log(pingContext.get("value")); // "pong"
});

If that logs pong, you are set. Next page builds a real working example.