---
source: https://iinventedlight.com/library/notes/node-dns.md
title: "Node.js dns - lookup vs resolve, promises API and custom resolvers"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js API docs); MIT (nodejs/node (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: node dns"
tags: [node, dns, lookup, resolve, networking, getaddrinfo]
client: Librarian
sources:
  - id: S1
    title: "DNS"
    publisher: Node.js API docs
    url: https://nodejs.org/api/dns.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "doc/api/dns.md"
    publisher: nodejs/node (GitHub)
    url: https://github.com/nodejs/node/blob/main/doc/api/dns.md
    accessed: 2026-11-18
    license: "MIT"
---
# 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

```js
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

- In practice `dns.lookup()` resolves a name almost always the same way the ping command does.
- Though `dns.lookup()` is asynchronous from JavaScript's perspective, it is implemented as a synchronous call to getaddrinfo(3) on libuv's threadpool, which can hurt performance; see UV_THREADPOOL_SIZE.
- Various networking APIs call `dns.lookup()` internally to resolve host names.
- `new Resolver()` creates an independent resolver for DNS requests. Setting the servers used for one resolver does not affect other resolvers.
- Changing nsswitch.conf or resolv.conf changes `lookup()` for all other programs on the same operating system.

## See also

- [node-http-and-url](https://iinventedlight.com/library/notes/node-http-and-url/)
- [node-events](https://iinventedlight.com/library/notes/node-events/)
- [docker-bridge-networks](https://iinventedlight.com/library/notes/docker-bridge-networks/)

## Claims

- id: C1
  claim: lookup uses OS facilities and may skip the network.
  source: S1
  evidence: "dns.lookup() uses the operating system facilities to perform name resolution."

- id: C2
  claim: resolve functions always query DNS on the network.
  source: S1
  evidence: "they always perform a DNS query on the network."

- id: C3
  claim: lookup runs getaddrinfo synchronously on the threadpool.
  source: S2
  evidence: "it is implemented as a synchronous call to getaddrinfo(3) that runs"

## Sources

- [S1] DNS. Node.js API docs. https://nodejs.org/api/dns.html . License: MIT. Accessed 2026-11-18.

- [S2] doc/api/dns.md. nodejs/node (GitHub). https://github.com/nodejs/node/blob/main/doc/api/dns.md . License: MIT. Accessed 2026-11-18.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
