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, andreverseresolve,resolve4,resolve6,resolveAny, and record-specific resolvers for CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TLSA, and TXTgetServers,setServers,getDefaultResultOrder, andsetDefaultResultOrder- independent
Resolverinstances withcancel()
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.