Query DNS records using node:dns, DNS over HTTP and/or DNSJSON over HTTP.
A list of publicly accessible servers can be found here.
Example: Using the default resolver
import { dns } from'@multiformats/dns'
constresolver = dns()
// resolve A records with a 5s timeout constresult = awaitdns.query('google.com', { signal:AbortSignal.timeout(5000) })
Example: Using per-TLD resolvers
import { dns } from'@multiformats/dns' import { dnsJsonOverHttps } from'@multiformats/dns/resolvers'
constresolver = dns({ resolvers: { // will only be used to resolve `.com` addresses 'com.':dnsJsonOverHttps('https://cloudflare-dns.com/dns-query'),
// this can also be an array, resolvers will be shuffled and tried in // series 'net.': [ dnsJsonOverHttps('https://dns.google/resolve'), dnsJsonOverHttps('https://dns.pub/dns-query') ],
// will only be used to resolve all other addresses '.':dnsJsonOverHttps('https://dnsforge.de/dns-query'), } })
// resolve only TXT records constresult = awaitdns.query('google.com', { types: [ RecordType.TXT ] })
Caching
Individual Aanswers are cached so. If you make a request, for which all
record types are cached, all values will be pulled from the cache.
If any of the record types are not cached, a new request will be resolved as
if none of the records were cached, and the cache will be updated to include
the new results.
Query DNS records using
node:dns
, DNS over HTTP and/or DNSJSON over HTTP.A list of publicly accessible servers can be found here.
Example: Using the default resolver
Example: Using per-TLD resolvers
Example: Query for specific record types
Caching
Individual Aanswers are cached so. If you make a request, for which all record types are cached, all values will be pulled from the cache.
If any of the record types are not cached, a new request will be resolved as if none of the records were cached, and the cache will be updated to include the new results.
Example: Ignoring the cache