Workers - Support for Node.js DNS, Net, and Timer APIs
Cloudflare Workers with nodejs_compat now support Node.js DNS, Net, and Timer APIs, enabling TCP socket connections via net.Socket, DNS name resolution via node:dns, and scheduled function execution with setTimeout, setInterval, and setImmediate.
When using a Worker with the nodejs_compat compatibility flag enabled, you can now use the following Node.js APIs:
node:net
You can use node:net ↗ to create a direct connection to servers via a TCP sockets
with net.Socket ↗.
import net from "node:net";
const exampleIP = "127.0.0.1";
export default {
async fetch(req) {
const socket = new net.Socket();
socket.connect(4000, exampleIP, function () {
console.log("Connected");
});
socket.write("Hello, Server!");
socket.end();
return new Response("Wrote to server", { status: 200 });
},
};index.tstsimport net from "node:net";
const exampleIP = "127.0.0.1";
export default {
async fetch(req): Promise<Response> {
const socket = new net.Socket();
socket.connect(4000, exampleIP, function () {
console.log("Connected");
});
socket.write("Hello, Server!");
socket.end();
return new Response("Wrote to server", { status: 200 });
},
} satisfies ExportedHandler;
Additionally, you can now use other APIs including net.BlockList ↗ and
net.SocketAddress ↗.
Note that net.Server ↗ is not supported.
node:dns
You can use node:dns ↗ for name resolution via DNS over HTTPS using
Cloudflare DNS ↗ at 1.1.1.1.
import dns from "node:dns";
let response = await dns.promises.resolve4("cloudflare.com", "NS");index.tstsimport dns from 'node:dns';
let response = await dns.promises.resolve4('cloudflare.com', 'NS');
All node:dns functions are available, except lookup, lookupService, and resolve which throw "Not implemented" errors when called.
node:timers
You can use node:timers ↗ to schedule functions to be called at some future period of time.
This includes setTimeout ↗ for calling a function after a delay,
setInterval ↗ for calling a function repeatedly,
and setImmediate ↗ for calling a function in the next iteration of the event loop.
import timers from "node:timers";
console.log("first");
timers.setTimeout(() => {
console.log("last");
}, 10);
timers.setTimeout(() => {
console.log("next");
});index.tstsimport timers from "node:timers";
console.log("first");
timers.setTimeout(() => {
console.log("last");
}, 10);
timers.setTimeout(() => {
console.log("next");
});Source: original entry ↗
More from Cloudflare
Follow Cloudflare to get its new changes in your feed and email digest.
Cloudflare One Client for macOS 2026.8.2100.0
GA release for macOS Cloudflare One Client with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster connects with lower memory use, and numerous reliability fixes across DNS, reauthentication, and client stability.
Cloudflare One Client for Windows 2026.8.2100.0
This GA release improves split tunnel reliability, adds support for non-RFC 1918 local networks, optimizes connection performance with faster reconnections and lower memory usage, and includes numerous bug fixes for DNS, registration, and network handling. The client now features a service recovery mechanism that automatically restarts on system unlock and better handles large hosts files without blocking traffic.
Cloudflare One Client for Linux 2026.8.2100.0
New GA release for Linux with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster tunnel reconnections, and lower memory usage. Includes numerous stability and reliability fixes for DNS, reconnection behavior, and crash issues.