Node.js core APIs land in Cloudflare Workers

Cloudflare has begun rolling out native support for Node.js core APIs in Workers, starting with AsyncLocalStorage, EventEmitter, Buffer, assert, and selected parts of util. These APIs are implemented directly in the open-source workerd runtime, meaning developers no longer need to bundle polyfills. Enabling the nodejs_compat compatibility flag makes them available immediately.

The implementation uses the node: specifier prefix (e.g., node:async_hooks, node:events) consistent with modern Node.js import syntax.

Async context tracking

The AsyncLocalStorage API solves the problem of propagating context through asynchronous code without threading parameters through every function call. Consider a request-ID logging scenario: without async context tracking, the request ID must be passed down through all intervening functions. With AsyncLocalStorage, application logic stays decoupled from the context while the logging utility can retrieve it at any depth.

The Workers implementation follows a subset of the API, deliberately omitting enterWith() and disable(), which the runtime considers brittle and error-prone. Internally, async operations capture the current "Asynchronous Context Frame"—a mapping of storage cells—when initiated, and restore it when the operation resumes. For unhandledrejection events, context propagates from the rejected promise itself, unlike other EventTarget events which use whichever frame is active at emission time.

Workers can also use AsyncLocalStorage.snapshot() to manually capture context and propagate it later. The runtime expects this implementation to align with the TC-39 AsyncContext proposal, which is inspired by AsyncLocalStorage and aims to bring async context tracking to the JavaScript language standard.

EventEmitter and Buffer

EventEmitter underpins many higher-level Node.js modules such as streams, crypto, and networking. The Workers implementation supports the full API, including the captureRejections option for better handling of async event handlers.

The Buffer API retains its extended binary-manipulation capabilities—built-in base64 and hex codecs, byte-order operations, and encoding-aware substring matching—while extending from Uint8Array. Because of that inheritance, Buffer instances plug directly into existing Workers APIs that accept Uint8Array, including Response constructors and streams.

Assertions and utility functions

The assert module runs exclusively in Node.js "strict assertion mode." This means non-strict methods such as deepEqual() behave as their strict equivalents, e.g., deepStrictEqual().

From util, Workers ships promisify and callbackify to convert between callback-style and Promise-based code, along with util.types for reliable built-in type checking. The util.types implementation does not currently include isExternal(), isProxy(), isKeyObject(), or isWebAssemblyCompiledModule().

On the roadmap

String decoder, streams, and crypto APIs are in active development. Once released, they'll appear incrementally in the runtime; any Worker using the nodejs_compat flag will gain access without code changes.