Resolves a host name (e.g. 'nodejs.org') into the first found A (IPv4) or
AAAA (IPv6) record. All option properties are optional. If options is an
integer, then it must be 4 or 6 – if options is 0 or not provided, then
IPv4 and IPv6 addresses are both returned if found.
With the all option set to true, the arguments for callback change to (err, addresses), with addresses being an array of objects with the
properties address and family.
On error, err is an Error object, where err.code is the error code.
Keep in mind that err.code will be set to 'ENOTFOUND' not only when
the host name does not exist but also when the lookup fails in other ways
such as no available file descriptors.
dns.lookup() does not necessarily have anything to do with the DNS protocol.
The implementation uses an operating system facility that can associate names
with addresses and vice versa. This implementation can have subtle but
important consequences on the behavior of any Node.js program. Please take some
time to consult the Implementation considerations section
before using dns.lookup().
// When options.all is true, the result will be an Array. options.all = true; dns.lookup('example.com', options, (err, addresses) => console.log('addresses: %j', addresses)); // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
If this method is invoked as its util.promisify() ed
version, and all is not set to true, it returns a Promise for an Object with address and family properties.
Resolves a host name (e.g.
'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. Alloptionproperties are optional. Ifoptionsis an integer, then it must be4or6– ifoptionsis0or not provided, then IPv4 and IPv6 addresses are both returned if found.With the
alloption set totrue, the arguments forcallbackchange to(err, addresses), withaddressesbeing an array of objects with the propertiesaddressandfamily.On error,
erris anErrorobject, whereerr.codeis the error code. Keep in mind thaterr.codewill be set to'ENOTFOUND'not only when the host name does not exist but also when the lookup fails in other ways such as no available file descriptors.dns.lookup()does not necessarily have anything to do with the DNS protocol. The implementation uses an operating system facility that can associate names with addresses and vice versa. This implementation can have subtle but important consequences on the behavior of any Node.js program. Please take some time to consult the Implementation considerations section before usingdns.lookup().Example usage:
If this method is invoked as its util.promisify() ed version, and
allis not set totrue, it returns aPromisefor anObjectwithaddressandfamilyproperties.