Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/content/docs/workers/configuration/compatibility-flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,11 @@ Compatibility flags can be set when uploading a Worker using the [Workers Script

## Node.js compatibility flag

:::note
You can opt into improved Node.js compatibility by using `nodejs_compat_v2` instead of `nodejs_compat`. This provides the functionality of `nodejs_compat`, but
additionally you can import Node.js modules without the `node:` prefix and use polyfilled Node.js modules and globals that are not available with `nodejs_compat`.

On September 23, 2024, `nodejs_compat` will use the improved Node.js compatibility currently enabled with `nodejs_compat_v2`. This will require updating your
compatibility_date to 2024-09-23 or later.
:::

A [growing subset](/workers/runtime-apis/nodejs/) of Node.js APIs are available directly as [Runtime APIs](/workers/runtime-apis/nodejs), with no need to add polyfills to your own code. To enable these APIs in your Worker, add the `nodejs_compat` compatibility flag to your `wrangler.toml`:
import { Render } from "~/components";

<Render file="nodejs_compat" product="workers" />

A [growing subset](/workers/runtime-apis/nodejs/) of Node.js APIs are available directly as [Runtime APIs](/workers/runtime-apis/nodejs), with no need to add polyfills to your own code. To enable these APIs in your Worker, only the `nodejs_compat` compatibility flag is required:

<WranglerConfig>

Expand All @@ -69,8 +63,6 @@ As additional Node.js APIs are added, they will be made available under the `nod

The Node.js `AsyncLocalStorage` API is a particularly useful feature for Workers. To enable only the `AsyncLocalStorage` API, use the `nodejs_als` compatibility flag.



<WranglerConfig>

```toml title="wrangler.toml"
Expand Down
19 changes: 3 additions & 16 deletions src/content/docs/workers/runtime-apis/nodejs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,9 @@ You can view which APIs are supported using the [Node.js compatability matrix](h

## Get Started

To enable both built-in runtime APIs and polyfills for your Worker or Pages project, add the [`nodejs_compat`](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) [compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) to your `wrangler.toml`, and set your compatibility date to September 23rd, 2024 or later.
import { Render } from "~/components";

import { WranglerConfig } from "~/components";

<WranglerConfig>

```toml title="wrangler.toml"
compatibility_flags = [ "nodejs_compat" ]
compatibility_date = "2024-09-23"
```

</WranglerConfig>

:::note
As of September 23rd, 2024, the `nodejs_compat` compatibility flag enables the exact same behavior as the `nodejs_compat_v2` compatibility flag, as long as your compatibility date is set to September 23rd, 2024 or later.
:::
<Render file="nodejs_compat" product="workers" />

## Built-in Node.js Runtime APIs

Expand Down Expand Up @@ -68,7 +55,7 @@ If an API you wish to use is missing and you want to suggest that Workers suppor

To enable only the Node.js `AsyncLocalStorage` API, use the `nodejs_als` compatibility flag.


import { WranglerConfig } from "~/components";

<WranglerConfig>

Expand Down
20 changes: 20 additions & 0 deletions src/content/partials/workers/nodejs_compat.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
{}
---

import { WranglerConfig } from "~/components";

To enable both built-in runtime APIs and polyfills for your Worker or Pages project, add the [`nodejs_compat`](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) [compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) to your `wrangler.toml`, and set your compatibility date to September 23rd, 2024 or later. This will enable [Node.js compatibility](/workers/runtime-apis/nodejs/) for your Workers project.

<WranglerConfig>

```toml title="wrangler.toml"
compatibility_flags = [ "nodejs_compat" ]
compatibility_date = "2024-09-23"
```

</WranglerConfig>

:::note
As of September 23rd, 2024, the `nodejs_compat` compatibility flag enables the exact same behavior as the `nodejs_compat_v2` compatibility flag, as long as your compatibility date is set to September 23rd, 2024 or later.
:::
Loading