node:dns API Reference

Callback and Promise-based DNS resolution

Both callback and Promise APIs are available:

import dns from "node:dns/promises";

const result = await dns.lookup("localhost");
console.log(result.address, result.family);

Operations

  • lookup, lookupService, and reverse
  • resolve, resolve4, resolve6, resolveAny, and record-specific resolvers for CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TLSA, and TXT
  • getServers, setServers, getDefaultResultOrder, and setDefaultResultOrder
  • independent Resolver instances with cancel()

node:dns/promises provides Promise-returning counterparts. The callback module exports standard DNS error-code constants such as NOTFOUND, SERVFAIL, REFUSED, and CANCELLED.

Results depend on the host resolver, configured servers, and network policy. Use localhost for an offline smoke test; public-host examples require working DNS and permitted network access.