Skip to content

Node.js compatibility

When you write a Worker, you may need to import packages from npm. Many npm packages rely on APIs from the Node.js runtime, and will not work unless these Node.js APIs are available.

Cloudflare Workers provides a subset of Node.js APIs in two forms:

  1. As built-in APIs provided by the Workers Runtime. Most of these APIs are full implementations of the corresponding Node.js APIs, while a few are partially supported.
  2. As polyfill shim implementations that Wrangler adds to your Worker's code, allowing it to import the module, but calling API methods will throw errors.

Get Started

To enable built-in Node.js APIs and add polyfills, add the nodejs_compat compatibility flag to your Wrangler configuration file, and ensure that your Worker's compatibility date is 2024-09-23 or later. Learn more about the Node.js compatibility flag and v2.

JSONC
{
"compatibility_flags": ["nodejs_compat"],
// Set this to today's date
"compatibility_date": "2026-07-01",
}

Supported Node.js APIs

The runtime APIs from Node.js listed in this section with the status "🟢 supported" are currently natively supported in the Workers Runtime. Items listed as "🟡 partially supported" include usable APIs, but do not implement the complete Node.js API surface.

Deprecated or experimental APIs from Node.js, and APIs that do not fit in a serverless context, are not included in the supported API list in this section. Some import-only stubs for these APIs are listed separately in Non-functional stub modules.

API NameNatively supported by the Workers Runtime
Assertion testing🟢 supported
Asynchronous context tracking🟢 supported
Buffer🟢 supported
Console🟡 partially supported
Crypto🟢 supported
Debugger🟢 supported via Chrome DevTools integration
Diagnostics Channel🟢 supported
DNS🟡 partially supported
Errors🟢 supported
Events🟢 supported
File system🟢 supported
Globals🟢 supported
HTTP🟢 supported
HTTPS🟢 supported
Module🟡 partially supported
Net🟢 supported
OS🟡 partially supported
Path🟢 supported
Performance hooks🟡 partially supported
Process🟢 supported
Punycode (deprecated)🟢 supported
Query strings🟢 supported
Stream🟢 supported
String decoder🟢 supported
Test runner🟡 partially supported
Timers🟢 supported
TLS/SSL🟡 partially supported
URL🟢 supported
Utilities🟢 supported
Web Crypto API🟢 supported
Web Streams API🟢 supported
Zlib🟢 supported

Unless otherwise specified, native implementations of Node.js APIs in Workers are intended to match the implementation in the Current release of Node.js.

If an API you wish to use is missing and you want to suggest that Workers support it, please add a post or comment in the Node.js APIs discussions category on GitHub.

Non-functional stub modules

Some Node.js modules are available as non-functional stubs. A stub can be imported or required, but does not provide a working implementation of the underlying Node.js API. These stubs exist so packages that check for the presence of a module can load in Workers, but they are not suitable for direct use in application code.

The following stubs are enabled automatically only when the nodejs_compat compatibility flag is enabled and your Worker's compatibility date is on or after the date shown. To enable one earlier, add the corresponding enable flag. To keep one unavailable after that date, add the corresponding disable flag.

Stub moduleEnabled with nodejs_compat on or afterEnable flagDisable flag
node:http22025-09-01enable_nodejs_http2_moduledisable_nodejs_http2_module
node:vm2025-10-01enable_nodejs_vm_moduledisable_nodejs_vm_module
node:cluster2025-12-04enable_nodejs_cluster_moduledisable_nodejs_cluster_module
node:domain2025-12-04enable_nodejs_domain_moduledisable_nodejs_domain_module
node:trace_events2025-12-04enable_nodejs_trace_events_moduledisable_nodejs_trace_events_module
node:wasi2025-12-04enable_nodejs_wasi_moduledisable_nodejs_wasi_module
node:_stream_wrap2026-01-29enable_nodejs_stream_wrap_moduledisable_nodejs_stream_wrap_module
node:dgram2026-01-29enable_nodejs_dgram_moduledisable_nodejs_dgram_module
node:inspector2026-01-29enable_nodejs_inspector_moduledisable_nodejs_inspector_module
node:sqlite2026-01-29enable_nodejs_sqlite_moduledisable_nodejs_sqlite_module
node:child_process2026-03-17enable_nodejs_child_process_moduledisable_nodejs_child_process_module
node:readline2026-03-17enable_nodejs_readline_moduledisable_nodejs_readline_module
node:repl2026-03-17enable_nodejs_repl_moduledisable_nodejs_repl_module
node:tty2026-03-17enable_nodejs_tty_moduledisable_nodejs_tty_module
node:v82026-03-17enable_nodejs_v8_moduledisable_nodejs_v8_module
node:worker_threads2026-03-17enable_nodejs_worker_threads_moduledisable_nodejs_worker_threads_module

Node.js API Polyfills

Node.js APIs that are not yet supported in the Workers runtime are polyfilled via Wrangler, which uses unenv. If the nodejs_compat compatibility flag is enabled, and your Worker's compatibility date is 2024-09-23 or later, Wrangler will automatically inject polyfills into your Worker's code.

Adding polyfills maximizes compatibility with existing npm packages by providing modules with mocked methods. Calling these mocked methods will either noop or will throw an error with a message like:

[unenv] <method name> is not implemented yet!

This allows you to import packages that use these Node.js modules, even if certain methods are not supported.

Enable only AsyncLocalStorage

If you need to enable only the Node.js AsyncLocalStorage API, you can enable the nodejs_als compatibility flag:

JSONC
{
"compatibility_flags": ["nodejs_als"],
}