DNS over HTTP resolver
Isomorphic DNS over HTTP resolver using fetch.
API based on Node.js' dns promises API, allowing the native dns
module to be used if available when relying on this API.
npm i dns-over-http-resolver
const DnsOverHttpResolver = require('dns-over-http-resolver')
const dohResolver = new DnsOverHttpResolver(options)
Cloudflare and Google DNS servers are used by default. They can be replaced via the API.
You can also use require('dns').promises
in Node.js in lieu of this module.
You can provide the following options for the DnsOverHttpResolver:
Name | Type | Description | Default |
---|---|---|---|
maxCache | number |
maximum number of cached dns records | 100 |
Uses the DNS protocol to resolve the given host name into a DNS record.
Name | Type | Description |
---|---|---|
hostname | string |
host name to resolve |
[rrType] | string |
resource record type (default: 'A') |
Type | Description |
---|---|
Promise<Array<string>> |
returns a Promise resolving a DNS record according to its type |
const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()
const hostname = 'google.com'
const recordType = 'TXT'
const dnsRecord = await resolver.resolve(hostname, recordType)
Uses the DNS protocol to resolve the given host name into IPv4 addresses.
Name | Type | Description |
---|---|---|
hostname | string |
host name to resolve |
Type | Description |
---|---|
Promise<Array<string>> |
returns a Promise resolving IPv4 addresses |
const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()
const hostname = 'google.com'
const address = await resolver.resolve4(hostname) // ['216.58.212.142']
Uses the DNS protocol to resolve the given host name into IPv6 addresses.
Name | Type | Description |
---|---|---|
hostname | string |
host name to resolve |
Type | Description |
---|---|
Promise<Array<string>> |
returns a Promise resolving IPv6 addresses |
const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()
const hostname = 'google.com'
const address = await resolver.resolve6(hostname) // ['2a00:1450:4001:801::200e']
Uses the DNS protocol to resolve the given host name into a Text Record.
Name | Type | Description |
---|---|---|
hostname | string |
host name to resolve |
Type | Description |
---|---|
Promise<Array<Array<string>>> |
returns a Promise resolving a Text Record |
const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()
const hostname = 'google.com'
const address = await resolver.resolveTxt(hostname) // [['v=spf1 -all']]
Get an array of the IP addresses currently configured for DNS resolution. These addresses are formatted according to RFC 5952. It can include a custom port.
Type | Description |
---|---|
Array<string> |
returns array of DNS servers used |
const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()
const servers = resolver.getServers()
Sets the IP address and port of servers to be used when performing DNS resolution. Note that the servers order will be randomized on each request for load distribution.
Name | Type | Description |
---|---|---|
servers | Array<string> |
Array of RFC 5952 formatted addresses. |
const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()
resolver.setServers(['https://cloudflare-dns.com/dns-query'])
Feel free to dive in! Open an issue or submit PRs.
MIT © Vasco Santos