Skip to content

Commit 55213cc

Browse files
committed
Minor tweaks in response to feedback
1 parent b3dc231 commit 55213cc

File tree

11 files changed

+33
-32
lines changed

11 files changed

+33
-32
lines changed

src/content/changelogs-next/2025-01-22-nodejs-compat-improvements.mdx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
2-
title: Improved Node.js compatibility
3-
description: Node.js APIs from the node:dns, node:net, and node:timers modules are now available when using nodejs_compatibility.
2+
title: Support for Node.js DNS, Net, and Timer APIs in Workers
3+
description: Node.js APIs from the node:dns, node:net, and node:timers modules are now available when using nodejs_compat.
44
products:
55
- workers
6+
- pages
67
date: 2025-01-22T13:00:00Z
78
---
89

910
import { Render, PackageManagers, TypeScriptExample } from "~/components";
1011

11-
When using a Worker with [nodejs_compatability](/workers/runtime-apis/nodejs/) enabled, you can now use the following Node.js APIs:
12+
When using a Worker with the [`nodejs_compat`](/workers/runtime-apis/nodejs/) compatibility flag enabled, you can now use the following Node.js APIs:
1213

1314
- [`node:net`](/workers/runtime-apis/nodejs/net/)
1415
- [`node:dns`](/workers/runtime-apis/nodejs/dns/)
@@ -20,8 +21,6 @@ You can use [`net.Socket`](https://nodejs.org/api/net.html#class-netsocket) to c
2021
This can be useful when connecting to databases such as [MySQL](https://www.mysql.com/) or [PostgreSQL](https://www.postgresql.org/),
2122
though if possible, using [Hyperdrive Connection Pooling](/hyperdrive/configuration/how-hyperdrive-works/#connection-pooling) is preferable.
2223

23-
These functions use [`connect`](/workers/runtime-apis/tcp-sockets/#connect) functionality from the built-in `cloudflare:sockets` module.
24-
2524
<TypeScriptExample filename="index.ts">
2625
```ts
2726
import net from 'node:net';
@@ -49,7 +48,7 @@ export default {
4948
Additionally, you can now use other APIs incliding [`net.BlockList`](https://nodejs.org/api/net.html#class-netblocklist) and
5049
[`net.SocketAddress`](https://nodejs.org/api/net.html#class-netsocketaddress).
5150

52-
Note that the [`net.Server`](https://nodejs.org/api/net.html#class-netserver) module is not supported.
51+
Note that [`net.Server`](https://nodejs.org/api/net.html#class-netserver) is not supported.
5352

5453
#### node:dns
5554

@@ -60,20 +59,20 @@ You can use [`node:dns`](https://nodejs.org/api/dns.html) for name resolution vi
6059
```ts
6160
import dns from "node:dns";
6261
63-
dns.lookup("example.org", (_err: any, address: string, ipFamily: number) => {
64-
console.log("address: %j family: IPv%s", address, ipFamily);
62+
dns.lookup("example.org", (_err: any, address: string, ipFamily: number) =>
63+
console.log(`address: ${address} family: IPv${ipFamily}`);
6564
````
6665
6766
</TypeScriptExample>
6867
69-
All `node:dns` functions are available.
68+
All `node:dns` functions are available, except `lookup`, `lookupService`, and `resolve` which throw "Not implemented" errors when called.
7069
7170
#### node:timers
7271
7372
You can use [`node:timers`](https://nodejs.org/api/timers.html) to schedule functions to be called at some future period of time.
7473
7574
This includes [`setTimeout`](https://nodejs.org/api/timers.html#settimeoutcallback-delay-args) for calling a function after a delay,
76-
[`setInterval`](https://nodejs.org/api/timers.html#clearintervaltimeout) for calling a function repeatedly,
75+
[`setInterval`](https://nodejs.org/api/timers.html#setintervalcallback-delay-args) for calling a function repeatedly,
7776
and [`setImmediate`](https://nodejs.org/api/timers.html#setimmediatecallback-args) for calling a function in the next iteration of the event loop.
7877
7978
<TypeScriptExample filename="index.ts">
@@ -91,8 +90,3 @@ console.log("next");
9190

9291
```
9392
</TypeScriptExample>
94-
95-
Note that due to [security-based restrictions on timers](/workers/reference/security-model/#step-1-disallow-timers-and-multi-threading) in Workers,
96-
timers are limited to returning the time of the last I/O. This means that while setTimeout, setInterval, and setImmediate will defer your function execution
97-
until after other events have run, they will not delay them for the full time specified.
98-
```

src/content/docs/workers/runtime-apis/nodejs/assert.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Assert
3+
title: assert
44
---
55

66
import { Render } from "~/components";

src/content/docs/workers/runtime-apis/nodejs/dns.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: DNS
3+
title: dns
44
---
55

66
import { Render, TypeScriptExample } from "~/components";
@@ -13,11 +13,15 @@ You can use [`node:dns`](https://nodejs.org/api/dns.html) for name resolution vi
1313
```js
1414
import dns from "node:dns";
1515

16-
dns.lookup("example.org", (err, address, ipFamily) => {
17-
console.log("address: %j family: IPv%s", address, ipFamily);
16+
dns.lookup("example.org", (_err: any, address: string, ipFamily: number) =>
17+
console.log(`address: ${address} family: IPv${ipFamily}`);
1818
});
1919
```
2020

21-
Note that DNS requests will execute a subrequest, counts for your [Worker's subrequest limit](/workers/platform/limits/#subrequests).
21+
:::note
22+
23+
DNS requests will execute a subrequest, counts for your [Worker's subrequest limit](/workers/platform/limits/#subrequests).
24+
25+
:::
2226

2327
The full `node:dns` API is documented in the [Node.js documentation for `node:dns`](https://nodejs.org/api/dns.html).

src/content/docs/workers/runtime-apis/nodejs/net.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Net
3+
title: net
44
---
55

66
import { Render, TypeScriptExample } from "~/components";
@@ -40,6 +40,6 @@ export default {
4040
Additionally, other APIs such as [`net.BlockList`](https://nodejs.org/api/net.html#class-netblocklist)
4141
and [`net.SocketAddress`](https://nodejs.org/api/net.html#class-netsocketaddress) are available.
4242

43-
Note that the [`net.Server`](https://nodejs.org/api/net.html#class-netserver) module is not supported by Workers.
43+
Note that the [`net.Server`](https://nodejs.org/api/net.html#class-netserver) class is not supported by Workers.
4444

4545
The full `node:net` API is documented in the [Node.js documentation for `node:net`](https://nodejs.org/api/net.html).

src/content/docs/workers/runtime-apis/nodejs/path.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Path
3+
title: path
44
---
55

66
import { Render } from "~/components";

src/content/docs/workers/runtime-apis/nodejs/process.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Process
3+
title: process
44

55
---
66

src/content/docs/workers/runtime-apis/nodejs/test.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Test
3+
title: test
44

55
---
66

src/content/docs/workers/runtime-apis/nodejs/timers.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Timers
3+
title: timers
44
---
55

66
import { Render, TypeScriptExample } from "~/components";
@@ -19,18 +19,21 @@ import timers from 'node:timers';
1919

2020
console.log('first');
2121
timers.setTimeout(() => {
22-
console.log('last');
22+
console.log('last');
2323
}, 10);
2424

2525
timers.setTimeout(() => {
26-
console.log('next');
26+
console.log('next');
2727
});
2828

2929
```
3030
</TypeScriptExample>
3131

32-
Note that due to [security-based restrictions on timers](/workers/reference/security-model/#step-1-disallow-timers-and-multi-threading) in Workers,
32+
:::note
33+
Due to [security-based restrictions on timers](/workers/reference/security-model/#step-1-disallow-timers-and-multi-threading) in Workers,
3334
timers are limited to returning the time of the last I/O. This means that while setTimeout, setInterval, and setImmediate will defer your function execution
3435
until after other events have run, they will not delay them for the full time specified.
3536

37+
:::
38+
3639
The full `node:timers` API is documented in the [Node.js documentation for `node:timers`](https://nodejs.org/api/timers.html).

src/content/docs/workers/runtime-apis/nodejs/url.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: URL
3+
title: url
44

55
---
66

src/content/docs/workers/runtime-apis/nodejs/util.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Util
3+
title: util
44

55
---
66

0 commit comments

Comments
 (0)