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)
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 neededconst dnsRecordsStream = getAllDnsRecordsStream('shopify.com')// decoder to convert the Uint8Array to a stringconst 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.