Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/LayeredStudio/dns-records/llms.txt

Use this file to discover all available pages before exploring further.

Explore practical examples demonstrating different use cases for DNS record lookups.

Getting specific record types

Retrieve DNS records by type for any domain.
import { type DnsRecord, getDnsRecords } from '@layered/dns-records'

const domain = 'apple.com'

const aRecords: DnsRecord[] = await getDnsRecords(domain, 'A')

console.log(`A records for ${domain}`)
console.log(aRecords)

Verifying DNS records

Check for specific DNS record values, such as SPF records for email authentication.
import { type DnsRecord, getDnsRecords } from '@layered/dns-records'

const domain = 'example.com'

const txtRecords: DnsRecord[] = await getDnsRecords(domain, 'TXT')

console.log(`${txtRecords.length} TXT records found for ${domain}`)
console.log(txtRecords)

const txtSpfRecord = txtRecords.find(r => r.data.includes('v=spf1'))

console.log(`SPF record:`, txtSpfRecord ? '✅ found' : '❌ not found')
Use the find() method to locate specific records by their data content, such as SPF, DKIM, or DMARC records.

Getting all DNS records

Discover all DNS records for a domain with a single function call.
import { type DnsRecord, getAllDnsRecords } from '@layered/dns-records'

const allDnsRecords: DnsRecord[] = await getAllDnsRecords('example.com')

console.log(allDnsRecords)
console.log(allDnsRecords.length)
The getAllDnsRecords() function automatically discovers subdomains and detects wildcard records.

Using different DNS resolvers

Specify which DNS resolver to use for queries.
import { DnsRecord, getAllDnsRecords } from '@layered/dns-records'

const domain = 'render.com'

const dnsRecords = await getAllDnsRecords(domain, {
  resolver: 'node-dig',
})

console.log(dnsRecords)
console.log(`${dnsRecords.length} DNS Records found ${domain} 👆`)
NameRuntime compatibilityNotes
cloudflare-dnsWorks on allRequires fetch as global
google-dnsWorks on allRequires fetch as global
node-dnsWorks only in Node.jsUses Node.js DNS module
node-digWorks only in Node.jsUses dig command
deno-dnsWorks only in DenoUses Deno.resolveDns

Streaming DNS records

Process DNS records as they’re discovered using the streaming API.
import { type DnsRecord, getAllDnsRecordsStream, parseDnsRecord } from '@layered/dns-records'

// get the DNS Records stream. Notice await is not needed
const dnsRecordsStream = getAllDnsRecordsStream('shopify.com')

// decoder to convert the Uint8Array to a string
const decoder = new TextDecoder()

for await (const record of dnsRecordsStream) {
  // record is a Uint8Array, so we need to convert it to a string
  const dnsRecordLine = decoder.decode(record)
  console.log('DNS line', dnsRecordLine)

  // parse the DNS record line to a DnsRecord object
  const dnsRecord: DnsRecord = parseDnsRecord(dnsRecordLine)
  //console.log('DNS object', dnsRecord)
}
Use streaming when you need to process records immediately as they’re discovered, rather than waiting for all records to be retrieved.

Advanced options

Customize subdomain discovery with additional options.
import { getAllDnsRecords } from '@layered/dns-records'

const allRecords = await getAllDnsRecords('x.com', {
  resolver: 'cloudflare-dns',
  commonSubdomainsCheck: true,
  subdomains: ['extra-subdomain-to-check-for'],
})

console.log('DNS all records', allRecords)

Options explained

  • resolver - Which DNS resolver to use (defaults to best for current runtime)
  • commonSubdomainsCheck - Check for common subdomains like www, api, mail (default: true)
  • subdomains - Additional subdomains to check beyond the common ones