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:

import { promises } from 'node:dns';
const resolver = new promises.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
external var getServers: () -> ReadonlyArray<String>
Link copied to clipboard
external var setServers: (ReadonlyArray<String>) -> Unit

Functions

Link copied to clipboard
external 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 external fun resolve(hostname: String): ReadonlyArray<String>
suspend external fun resolve(hostname: String, rrtype: String): Any
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.ANY): ReadonlyArray<AnyRecord>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.CAA): ReadonlyArray<CaaRecord>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.MX): ReadonlyArray<MxRecord>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.NAPTR): ReadonlyArray<NaptrRecord>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.SOA): SoaRecord
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.SRV): ReadonlyArray<SrvRecord>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.StringRecord): ReadonlyArray<String>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.TLSA): ReadonlyArray<TlsaRecord>
suspend external fun resolve(hostname: String, rrtype: ResourceRecordType.TXT): ReadonlyArray<ReadonlyArray<String>>
Link copied to clipboard
suspend external fun resolve4(hostname: String): ReadonlyArray<String>
suspend external fun resolve4(hostname: String, options: ResolveOptions): Any
suspend external fun resolve4(hostname: String, options: ResolveWithTtlOptions): ReadonlyArray<RecordWithTtl>
Link copied to clipboard
external fun resolve4Async(hostname: String): Promise<ReadonlyArray<String>>
external fun resolve4Async(hostname: String, options: ResolveOptions): Promise<Any>
Link copied to clipboard
suspend external fun resolve6(hostname: String): ReadonlyArray<String>
suspend external fun resolve6(hostname: String, options: ResolveOptions): Any
suspend external fun resolve6(hostname: String, options: ResolveWithTtlOptions): ReadonlyArray<RecordWithTtl>
Link copied to clipboard
external fun resolve6Async(hostname: String): Promise<ReadonlyArray<String>>
external fun resolve6Async(hostname: String, options: ResolveOptions): Promise<Any>
Link copied to clipboard
suspend external fun resolveAny(hostname: String): ReadonlyArray<AnyRecord>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveCaa(hostname: String): ReadonlyArray<CaaRecord>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveCname(hostname: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveMx(hostname: String): ReadonlyArray<MxRecord>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveNaptr(hostname: String): ReadonlyArray<NaptrRecord>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveNs(hostname: String): ReadonlyArray<String>
Link copied to clipboard
external fun resolveNsAsync(hostname: String): Promise<ReadonlyArray<String>>
Link copied to clipboard
suspend external fun resolvePtr(hostname: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveSoa(hostname: String): SoaRecord
Link copied to clipboard
external fun resolveSoaAsync(hostname: String): Promise<SoaRecord>
Link copied to clipboard
suspend external fun resolveSrv(hostname: String): ReadonlyArray<SrvRecord>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveTlsa(hostname: String): ReadonlyArray<TlsaRecord>
Link copied to clipboard
Link copied to clipboard
suspend external fun resolveTxt(hostname: String): ReadonlyArray<ReadonlyArray<String>>
Link copied to clipboard
Link copied to clipboard
suspend external fun reverse(ip: String): ReadonlyArray<String>
Link copied to clipboard
Link copied to clipboard
external 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.