Here’s a complete example that demonstrates both functions:
import { getDnsRecords, getAllDnsRecords } from '@layered/dns-records'// Get specific record typesconst txtRecords = await getDnsRecords('google.com', 'TXT')console.log(`Found ${txtRecords.length} TXT records`)// Get MX records with specific resolverconst mxRecords = await getDnsRecords('android.com', 'MX', 'google-dns')console.log(`Found ${mxRecords.length} MX records`)// Discover all DNS recordsconst allRecords = await getAllDnsRecords('example.com')console.log(`Discovered ${allRecords.length} total DNS records`)// Advanced: Get all records with custom optionsconst customRecords = await getAllDnsRecords('shopify.com', { resolver: 'cloudflare-dns', commonSubdomainsCheck: true, subdomains: ['api', 'cdn', 'status'],})
name (string) - Fully qualified domain name (e.g., 'google.com' or 'mail.apple.com')
type (string, optional) - Record type: 'A', 'AAAA', 'TXT', 'MX', 'CNAME', 'NS', 'SOA', etc. Defaults to 'A'
resolver (string, optional) - DNS resolver to use: 'cloudflare-dns', 'google-dns', 'node-dns', 'node-dig', or 'deno-dns'. Auto-selected if not specified
interface DnsRecord { name: string // Fully qualified domain name type: string // Record type: A, AAAA, CNAME, MX, TXT, etc. ttl: number // Time to live (in seconds) data: string // Record data: IP for A/AAAA, fqdn for CNAME, etc.}