Skip to main content

dns

还没翻译译自英文(developers.cloudflare.com)本页 12 段都还没译

Note

For compatibility dates of 2026-08-04 or later, Workers enables both nodejs_compat and nodejs_compat_v2 by default. These flags are not used for these compatibility dates. Existing projects do not need to remove them when updating their compatibility date. For earlier dates, add nodejs_compat to your Wrangler configuration file to opt in. For instructions to turn off Node.js compatibility, refer to the Node.js compatibility flag.

You can use node:dns for name resolution via DNS over HTTPS using Cloudflare DNS at 1.1.1.1.

JavaScriptTypeScript

index.js
import 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.

Note

DNS requests will execute a subrequest, counts for your Worker's subrequest limit.

The full node:dns API is documented in the Node.js documentation for node:dns.