Skip to main content
promises.Resolver - dns - Node documentation
class promises.Resolver

Usage in Deno

import { promises } from "node:dns";

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()

Constructors

new
Resolver(options?: ResolverOptions)

Properties

Methods

cancel(): void

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

setLocalAddress(
ipv4?: string,
ipv6?: string,
): void

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.

If a v4 or v6 address is not specified, it is set to the default and the operating system will choose a local address automatically.

The resolver will use the v4 local address when making requests to IPv4 DNS servers, and the v6 local address when making requests to IPv6 DNS servers. The rrtype of resolution requests has no impact on the local address used.