Available resolvers
cloudflare-dns
Uses Cloudflare’s DNS over HTTPS (DoH) API to query DNS records.- Endpoint:
https://cloudflare-dns.com/dns-query - Format: JSON API
- Requirements: Global
fetchfunction - Runtime compatibility: Works in all JavaScript runtimes
google-dns
Uses Google’s DNS over HTTPS (DoH) API to query DNS records.- Endpoint:
https://dns.google/resolve - Format: JSON API
- Requirements: Global
fetchfunction - Runtime compatibility: Works in all JavaScript runtimes
Google DNS is the default resolver for most runtimes that aren’t Node.js or Cloudflare Workers.
node-dns
Uses the Node.js built-in DNS module to query DNS records.- Module:
node:dns - API: Uses native DNS resolution methods like
resolveAny,resolve4,resolve6, etc. - Requirements: Node.js runtime
- Runtime compatibility: Works only in Node.js
node-dig
Uses thedig command-line tool via Node.js child process.
- Command: Spawns
digprocess withspawnSync - Output: Parses dig’s text output
- Requirements: Node.js runtime and
digcommand installed on the system - Runtime compatibility: Works only in Node.js with dig available
deno-dns
Intended for Deno runtime usingDeno.resolveDns.
Runtime compatibility table
| Resolver | Node.js | Browser | Cloudflare Workers | Deno | Bun | Notes |
|---|---|---|---|---|---|---|
cloudflare-dns | ✓ | ✓ | ✓ | ✓ | ✓ | Requires fetch |
google-dns | ✓ | ✓ | ✓ | ✓ | ✓ | Requires fetch |
node-dns | ✓ | ✗ | ✗ | ✗ | ✓ | Node.js only |
node-dig | ✓ | ✗ | ✗ | ✗ | ✗ | Node.js + dig command |
deno-dns | ✗ | ✗ | ✗ | ✗ | ✗ | Not yet implemented |
Specifying a resolver
You can specify which resolver to use when callinggetDnsRecords or getAllDnsRecords:
Automatic resolver selection
If you don’t specify a resolver, the library automatically selects the best one for your runtime:/home/daytona/workspace/source/src/get-dns-records.ts:5:
Implementation details
How cloudflare-dns and google-dns work
How cloudflare-dns and google-dns work
Both resolvers use DNS over HTTPS (DoH) APIs that return JSON responses. The library:
- Constructs a URL with the domain name and record type
- Makes a fetch request with appropriate headers
- Parses the JSON response
- Maps DNS type numbers (1 for A, 28 for AAAA, etc.) to type strings
- Normalizes record data by removing trailing dots from FQDNs
/home/daytona/workspace/source/src/dns-resolvers.ts:33 and :61 for implementation.How node-dns works
How node-dns works
The Node.js DNS module resolver uses native DNS resolution methods:
resolveAny()for all record typesresolve4()/resolve6()for A/AAAA records with TTLresolveCname()for CNAME recordsresolveMx()for MX recordsresolveNs()for NS recordsresolveSoa()for SOA recordsresolveTxt()for TXT recordsresolveCaa()for CAA records
/home/daytona/workspace/source/src/dns-resolvers.ts:162 for implementation.How node-dig works
How node-dig works
The dig resolver spawns a
dig command as a child process with optimized flags:+noall- Don’t display any text sections+answer- Except the answer section+cdflag- Skip DNSSEC checks for faster queries
/home/daytona/workspace/source/src/dns-resolvers.ts:96 for implementation.