Resolver

external class Resolver(source)

An independent resolver for DNS requests.

Creating a new resolver uses the default server settings. Setting the servers used for a resolver using resolver.setServers() does not affect other resolvers:

const { Resolver } = require('node:dns').promises;
const resolver = new Resolver();
resolver.setServers(['4.4.4.4']);

// This request will use the server at 4.4.4.4, independent of global settings.
resolver.resolve4('example.org').then((addresses) => {
// ...
});

// Alternatively, the same code can be written using async-await style.
(async function() {
const addresses = await resolver.resolve4('example.org');
})();

The following methods from the dnsPromises API are available:

  • resolver.getServers()

  • resolver.resolve()

  • resolver.resolve4()

  • resolver.resolve6()

  • resolver.resolveAny()

  • resolver.resolveCaa()

  • resolver.resolveCname()

  • resolver.resolveMx()

  • resolver.resolveNaptr()

  • resolver.resolveNs()

  • resolver.resolvePtr()

  • resolver.resolveSoa()

  • resolver.resolveSrv()

  • resolver.resolveTxt()

  • resolver.reverse()

  • resolver.setServers()

Since

v10.6.0

Constructors

Link copied to clipboard
constructor(options: ResolverOptions = definedExternally)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun cancel()

Cancel all outstanding DNS queries made by this resolver. The corresponding callbacks will be called with an error with code ECANCELLED.

Link copied to clipboard
suspend fun resolve(hostname: String): ReadonlyArray<String>
suspend fun resolve(hostname: String, rrtype: String): Any
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.A): ReadonlyArray<String>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.AAAA): ReadonlyArray<String>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.ANY): ReadonlyArray<AnyRecord>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.CAA): ReadonlyArray<CaaRecord>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.CNAME): ReadonlyArray<String>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.MX): ReadonlyArray<MxRecord>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.NS): ReadonlyArray<String>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.PTR): ReadonlyArray<String>
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.SOA): SoaRecord
suspend fun resolve(hostname: String, rrtype: ResourceRecordType.SRV): ReadonlyArray<SrvRecord>
Link copied to clipboard
suspend fun resolve4(hostname: String): ReadonlyArray<String>
suspend fun resolve4(hostname: String, options: ResolveOptions): Any
Link copied to clipboard
suspend fun resolve6(hostname: String): ReadonlyArray<String>
suspend fun resolve6(hostname: String, options: ResolveOptions): Any
Link copied to clipboard
suspend fun resolveAny(hostname: String): ReadonlyArray<AnyRecord>
Link copied to clipboard
Link copied to clipboard
suspend fun resolveCaa(hostname: String): ReadonlyArray<CaaRecord>
Link copied to clipboard
Link copied to clipboard
suspend fun resolveCname(hostname: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
suspend fun resolveMx(hostname: String): ReadonlyArray<MxRecord>
Link copied to clipboard
Link copied to clipboard
suspend fun resolveNaptr(hostname: String): ReadonlyArray<NaptrRecord>
Link copied to clipboard
Link copied to clipboard
suspend fun resolveNs(hostname: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
suspend fun resolvePtr(hostname: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
suspend fun resolveSoa(hostname: String): SoaRecord
Link copied to clipboard
Link copied to clipboard
suspend fun resolveSrv(hostname: String): ReadonlyArray<SrvRecord>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun reverse(ip: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
fun setLocalAddress(ipv4: String = definedExternally, ipv6: String = definedExternally)

The resolver instance will send its requests from the specified IP address. This allows programs to specify outbound interfaces when used on multi-homed systems.