DNS

dns.promises.lookup()

Uses the operating-system name service, not necessarily a DNS query. Numeric literals need no remote lookup. The all option returns an array. Tested on Node.js 22.16.0. Example output (one line per entry): ["127.0.0.1/4"].

Formal Syntax & Structure

nodejs syntaxnodejs
dnsPromises.lookup(hostname[, options])

Parameters & Attributes

NameTypeDescription
hostnamestringHost or literal address.
optionsobjectFamily, hints, order and all options.

Return Value

Promise<object | object[]>

Address record or records.

Working Example

Example Snippetnodejs
import { lookup } from 'node:dns/promises';console.log((await lookup('127.0.0.1', { all: true })).map(x => `${x.address}/${x.family}`).join(','));
Node.js Reference