You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enumerate Node.js APIs on main Node.js docs page (#20539)
* Enumerate Node.js APIs on main Node.js docs page
We don't currently have one place where you can look at-a-glance at what Node.js APIs are supported in Workers.
The compatibility matrix here is very cool, overly detailed for a quick reference on what is or isn't supported:
https://workers-nodejs-compat-matrix.pages.dev/
The clearest thing we can do is to provide a simple list of all non-deprecated, non-experimental APIs from Node.js (pulled this straight from the Node.js docs, in the same alphabetical order) — and state clearly which are supported, which we have partial support for, and which are not supported. And then link to our own relevant docs page.
There are a few here that are currently supported, but we haven't yet added a docs page for. We'll need to follow up on this, so that the sidebar includes all of the Node.js APIs we currently support in the Workers Runtime.
* Apply suggestions from code review
Co-authored-by: Yagiz Nizipli <[email protected]>
---------
Co-authored-by: Yagiz Nizipli <[email protected]>
Copy file name to clipboardExpand all lines: src/content/docs/workers/runtime-apis/nodejs/index.mdx
+61-24Lines changed: 61 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,11 @@ When you write a Worker, you may need to import packages from [npm](https://www.
12
12
Cloudflare Workers provides a subset of Node.js APIs in two forms:
13
13
14
14
1. As built-in APIs provided by the Workers Runtime
15
-
2. As polyfills that [Wrangler](/workers/wrangler/) adds to your Worker's code
16
-
17
-
You can view which APIs are supported using the [Node.js compatibility matrix](https://workers-nodejs-compat-matrix.pages.dev).
15
+
2. As polyfill shim implementations that [Wrangler](/workers/wrangler/) adds to your Worker's code, allowing it to import the module, but calling API methods will throw errors.
18
16
19
17
## Get Started
20
18
21
-
To enable built-in Node.js APIs and add polyfills, you need to add the `nodejs_compat` compatibility flag to your wrangler configuration. This also enables `nodejs_compat_v2` as long as your compatibility date is 2024-09-23 or later. [Learn more about the Node.js compatibility flag and v2](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).
22
-
19
+
To enable built-in Node.js APIs and add polyfills, add the `nodejs_compat` compatibility flag to your [wrangler configuration file](/workers/wrangler/configuration/), and ensure that your Worker's [compatibility date](/workers/configuration/compatibility-dates/) is 2024-09-23 or later. [Learn more about the Node.js compatibility flag and v2](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).
The following APIs from Node.js are provided directly by the Workers Runtime when either `nodejs_compat` or `nodejs_compat_v2` are enabled:
30
+
## Supported Node.js APIs
31
+
32
+
The runtime APIs from Node.js listed below as "🟢 supported" are currently natively supported in the Workers Runtime.
33
+
34
+
[Deprecated or experimental APIs from Node.js](https://nodejs.org/docs/latest/api/documentation.html#stability-index) are not included as part of the list below:
35
+
36
+
| API Name | Natively supported by the Workers Runtime |
Unless otherwise specified, native implementations of Node.js APIs in Workers are intended to match the implementation in the [Current release of Node.js](https://github.com/nodejs/release#release-schedule).
36
83
37
-
<DirectoryListing />
38
-
39
-
Unless otherwise specified, implementations of Node.js APIs in Workers are intended to match the implementation in the [Current release of Node.js](https://github.com/nodejs/release#release-schedule).
40
-
41
-
## Node.js API Polyfills
84
+
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
85
+
[Node.js APIs discussions category](https://github.com/cloudflare/workerd/discussions/categories/node-js-apis) on GitHub.
42
86
43
-
To enable built-in Node.js APIs and add polyfills, you need to add the `nodejs_compat` compatibility flag to your wrangler configuration. This also enables `nodejs_compat_v2` as long as your compatibility date is 2024-09-23 or later. [Learn more about the Node.js compatibility flag and v2](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).
87
+
### Node.js API Polyfills
44
88
45
-
Adding polyfills maximizes compatibility with existing npm packages, while recognizing that not all APIs from Node.js make sense in the context of serverless functions.
89
+
Node.js APIs that are not yet supported in the Workers runtime are polyfilled via [Wrangler](/workers/wrangler/), which uses [unenv](https://github.com/unjs/unenv). If the `nodejs_compat`[compatibility flag](/workers/configuration/compatibility-flags/) is enabled, and your Worker's [compatibility date](/workers/configuration/compatibility-dates/) is 2024-09-23 or later, Wrangler will automatically inject polyfills into your Worker's code.
46
90
47
-
Where it is possible to provide a fully functional polyfill of the relevant Node.js API, unenv will do so.
48
-
In cases where this is not possible, such as the [`fs`](https://nodejs.org/api/fs.html), unenv adds a module with mocked methods.
49
-
Calling these mocked methods will either noop or will throw an error with a message like:
91
+
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:
50
92
51
93
```
52
94
[unenv] <method name> is not implemented yet!
53
95
```
54
96
55
97
This allows you to import packages that use these Node.js modules, even if certain methods are not supported.
56
98
57
-
For a full list of APIs supported, including information on which are mocked, see the [Node.js compatibility matrix](https://workers-nodejs-compat-matrix.pages.dev).
58
-
59
-
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
60
-
[Node.js APIs discussions category](https://github.com/cloudflare/workerd/discussions/categories/node-js-apis) on GitHub.
61
-
62
99
## Enable only AsyncLocalStorage
63
100
64
-
To enable only the Node.js `AsyncLocalStorage` API, use the `nodejs_als` compatibility flag.
101
+
If you need to enable only the Node.js `AsyncLocalStorage` API, you can enable the `nodejs_als` compatibility flag:
0 commit comments