← All notes

Node.js dns - lookup vs resolve, promises API and custom resolvers

Answer: Use dns.lookup() to resolve a host name the way other applications on the same system do, including /etc/hosts. Use dns.resolve4(), dns.resolve() and dns.reverse() when you need actual DNS queries on the network. The node:dns module enables name resolution, but lookup() does not always use the DNS protocol.

Examples

import dns from 'node:dns/promises';

const { address, family } = await dns.lookup('example.org');
const all = await dns.lookup('example.org', { all: true });

const v4 = await dns.resolve4('archive.org');      // DNS query
const mx = await dns.resolveMx('example.org');
const names = await dns.reverse(v4[0]);

// Independent resolver with its own servers
const resolver = new dns.Resolver();
resolver.setServers(['1.1.1.1']);
await resolver.resolve4('example.org');

lookup vs resolve

| | dns.lookup() | dns.resolve*() / dns.reverse() | |---|---|---| | Uses | operating system facilities (getaddrinfo) | an actual DNS server | | Uses /etc/hosts configuration | uses it | does not use it | | Network | may not need any network communication | always perform a DNS query on the network | | Threadpool | runs on libuv's threadpool | does not use libuv's threadpool |

Rules

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, DNS; nodejs/node (GitHub), doc/api/dns.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, DNS; nodejs/node (GitHub), doc/api/dns.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.

Cite this

Permanent ID: iil:note:kaszhtr7

iinventedlight. 2026. "Node.js dns - lookup vs resolve, promises API and custom resolvers." iinventedlight Library, iil:note:kaszhtr7, version of 2026-11-18. https://iinventedlight.com/library/notes/node-dns/. License: CC-BY-4.0.

@misc{iil_note_kaszhtr7,
  author = {{iinventedlight}},
  title = {{Node.js dns - lookup vs resolve, promises API and custom resolvers}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/node-dns/},
  note = {Permanent ID iil:note:kaszhtr7. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-dns.md.