{ "type": "module", "source": "doc/api/dns.md", "modules": [ { "textRaw": "DNS", "name": "dns", "introduced_in": "v0.10.0", "stability": 2, "stabilityText": "Stable", "desc": "

The dns module contains functions belonging to two different categories:

\n

1) Functions that use the underlying operating system facilities to perform\nname resolution, and that do not necessarily perform any network communication.\nThis category contains only one function: dns.lookup(). Developers\nlooking to perform name resolution in the same way that other applications on\nthe same operating system behave should use dns.lookup().

\n

For example, looking up iana.org.

\n
const dns = require('dns');\n\ndns.lookup('iana.org', (err, address, family) => {\n  console.log('address: %j family: IPv%s', address, family);\n});\n// address: \"192.0.43.8\" family: IPv4\n
\n

2) Functions that connect to an actual DNS server to perform name resolution,\nand that always use the network to perform DNS queries. This category\ncontains all functions in the dns module except dns.lookup(). These\nfunctions do not use the same set of configuration files used by\ndns.lookup() (e.g. /etc/hosts). These functions should be used by\ndevelopers who do not want to use the underlying operating system's facilities\nfor name resolution, and instead want to always perform DNS queries.

\n

Below is an example that resolves 'archive.org' then reverse resolves the IP\naddresses that are returned.

\n
const dns = require('dns');\n\ndns.resolve4('archive.org', (err, addresses) => {\n  if (err) throw err;\n\n  console.log(`addresses: ${JSON.stringify(addresses)}`);\n\n  addresses.forEach((a) => {\n    dns.reverse(a, (err, hostnames) => {\n      if (err) {\n        throw err;\n      }\n      console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);\n    });\n  });\n});\n
\n

There are subtle consequences in choosing one over the other, please consult\nthe Implementation considerations section for more information.

", "modules": [ { "textRaw": "Class: `dns.Resolver`", "name": "class:_`dns.resolver`", "meta": { "added": [ "v8.3.0" ], "changes": [] }, "desc": "

An independent resolver for DNS requests.

\n

Note that creating a new resolver uses the default server settings. Setting\nthe servers used for a resolver using\nresolver.setServers() does not affect\nother resolvers:

\n
const { Resolver } = require('dns');\nconst resolver = new Resolver();\nresolver.setServers(['4.4.4.4']);\n\n// This request will use the server at 4.4.4.4, independent of global settings.\nresolver.resolve4('example.org', (err, addresses) => {\n  // ...\n});\n
\n

The following methods from the dns module are available:

\n", "modules": [ { "textRaw": "`resolver.cancel()`", "name": "`resolver.cancel()`", "meta": { "added": [ "v8.3.0" ], "changes": [] }, "desc": "

Cancel all outstanding DNS queries made by this resolver. The corresponding\ncallbacks will be called with an error with code ECANCELLED.

", "type": "module", "displayName": "`resolver.cancel()`" } ], "type": "module", "displayName": "Class: `dns.Resolver`" }, { "textRaw": "`dns.getServers()`", "name": "`dns.getservers()`", "meta": { "added": [ "v0.11.3" ], "changes": [] }, "desc": "\n

Returns an array of IP address strings, formatted according to rfc5952,\nthat are currently configured for DNS resolution. A string will include a port\nsection if a custom port is used.

\n\n
[\n  '4.4.4.4',\n  '2001:4860:4860::8888',\n  '4.4.4.4:1053',\n  '[2001:4860:4860::8888]:1053'\n]\n
", "type": "module", "displayName": "`dns.getServers()`" }, { "textRaw": "`dns.lookup(hostname[, options], callback)`", "name": "`dns.lookup(hostname[,_options],_callback)`", "meta": { "added": [ "v0.1.90" ], "changes": [ { "version": "v8.5.0", "pr-url": "https://github.com/nodejs/node/pull/14731", "description": "The `verbatim` option is supported now." }, { "version": "v1.2.0", "pr-url": "https://github.com/nodejs/node/pull/744", "description": "The `all` option is supported now." } ] }, "desc": "\n

Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or\nAAAA (IPv6) record. All option properties are optional. If options is an\ninteger, then it must be 4 or 6 – if options is not provided, then IPv4\nand IPv6 addresses are both returned if found.

\n

With the all option set to true, the arguments for callback change to\n(err, addresses), with addresses being an array of objects with the\nproperties address and family.

\n

On error, err is an Error object, where err.code is the error code.\nKeep in mind that err.code will be set to 'ENOENT' not only when\nthe hostname does not exist but also when the lookup fails in other ways\nsuch as no available file descriptors.

\n

dns.lookup() does not necessarily have anything to do with the DNS protocol.\nThe implementation uses an operating system facility that can associate names\nwith addresses, and vice versa. This implementation can have subtle but\nimportant consequences on the behavior of any Node.js program. Please take some\ntime to consult the Implementation considerations section before using\ndns.lookup().

\n

Example usage:

\n
const dns = require('dns');\nconst options = {\n  family: 6,\n  hints: dns.ADDRCONFIG | dns.V4MAPPED,\n};\ndns.lookup('example.com', options, (err, address, family) =>\n  console.log('address: %j family: IPv%s', address, family));\n// address: \"2606:2800:220:1:248:1893:25c8:1946\" family: IPv6\n\n// When options.all is true, the result will be an Array.\noptions.all = true;\ndns.lookup('example.com', options, (err, addresses) =>\n  console.log('addresses: %j', addresses));\n// addresses: [{\"address\":\"2606:2800:220:1:248:1893:25c8:1946\",\"family\":6}]\n
\n

If this method is invoked as its util.promisify()ed version, and all\nis not set to true, it returns a Promise for an Object with address and\nfamily properties.

", "modules": [ { "textRaw": "Supported getaddrinfo flags", "name": "supported_getaddrinfo_flags", "desc": "

The following flags can be passed as hints to dns.lookup().

\n", "type": "module", "displayName": "Supported getaddrinfo flags" } ], "type": "module", "displayName": "`dns.lookup(hostname[, options], callback)`" }, { "textRaw": "`dns.lookupService(address, port, callback)`", "name": "`dns.lookupservice(address,_port,_callback)`", "meta": { "added": [ "v0.11.14" ], "changes": [] }, "desc": "\n

Resolves the given address and port into a hostname and service using\nthe operating system's underlying getnameinfo implementation.

\n

If address is not a valid IP address, a TypeError will be thrown.\nThe port will be coerced to a number. If it is not a legal port, a TypeError\nwill be thrown.

\n

On an error, err is an Error object, where err.code is the error code.

\n
const dns = require('dns');\ndns.lookupService('127.0.0.1', 22, (err, hostname, service) => {\n  console.log(hostname, service);\n  // Prints: localhost ssh\n});\n
\n

If this method is invoked as its util.promisify()ed version, it returns a\nPromise for an Object with hostname and service properties.

", "type": "module", "displayName": "`dns.lookupService(address, port, callback)`" }, { "textRaw": "`dns.resolve(hostname[, rrtype], callback)`", "name": "`dns.resolve(hostname[,_rrtype],_callback)`", "meta": { "added": [ "v0.1.27" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array\nof the resource records. The callback function has arguments\n(err, records). When successful, records will be an array of resource\nrecords. The type and structure of individual results varies based on rrtype:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
rrtyperecords containsResult typeShorthand method
'A'IPv4 addresses (default)<string>dns.resolve4()
'AAAA'IPv6 addresses<string>dns.resolve6()
'ANY'any records<Object>dns.resolveAny()
'CNAME'canonical name records<string>dns.resolveCname()
'MX'mail exchange records<Object>dns.resolveMx()
'NAPTR'name authority pointer records<Object>dns.resolveNaptr()
'NS'name server records<string>dns.resolveNs()
'PTR'pointer records<string>dns.resolvePtr()
'SOA'start of authority records<Object>dns.resolveSoa()
'SRV'service records<Object>dns.resolveSrv()
'TXT'text records<string[]>dns.resolveTxt()
\n

On error, err is an Error object, where err.code is one of the\nDNS error codes.

", "type": "module", "displayName": "`dns.resolve(hostname[, rrtype], callback)`" }, { "textRaw": "`dns.resolve4(hostname[, options], callback)`", "name": "`dns.resolve4(hostname[,_options],_callback)`", "meta": { "added": [ "v0.1.16" ], "changes": [ { "version": "v7.2.0", "pr-url": "https://github.com/nodejs/node/pull/9296", "description": "This method now supports passing `options`, specifically `options.ttl`." } ] }, "desc": "\n

Uses the DNS protocol to resolve a IPv4 addresses (A records) for the\nhostname. The addresses argument passed to the callback function\nwill contain an array of IPv4 addresses (e.g.\n['74.125.79.104', '74.125.79.105', '74.125.79.106']).

", "type": "module", "displayName": "`dns.resolve4(hostname[, options], callback)`" }, { "textRaw": "`dns.resolve6(hostname[, options], callback)`", "name": "`dns.resolve6(hostname[,_options],_callback)`", "meta": { "added": [ "v0.1.16" ], "changes": [ { "version": "v7.2.0", "pr-url": "https://github.com/nodejs/node/pull/9296", "description": "This method now supports passing `options`, specifically `options.ttl`." } ] }, "desc": "\n

Uses the DNS protocol to resolve a IPv6 addresses (AAAA records) for the\nhostname. The addresses argument passed to the callback function\nwill contain an array of IPv6 addresses.

", "type": "module", "displayName": "`dns.resolve6(hostname[, options], callback)`" }, { "textRaw": "`dns.resolveAny(hostname, callback)`", "name": "`dns.resolveany(hostname,_callback)`", "desc": "\n

Uses the DNS protocol to resolve all records (also known as ANY or * query).\nThe ret argument passed to the callback function will be an array containing\nvarious types of records. Each object has a property type that indicates the\ntype of the current record. And depending on the type, additional properties\nwill be present on the object:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
TypeProperties
'A'address/ttl
'AAAA'address/ttl
'CNAME'value
'MX'Refer to dns.resolveMx()
'NAPTR'Refer to dns.resolveNaptr()
'NS'value
'PTR'value
'SOA'Refer to dns.resolveSoa()
'SRV'Refer to dns.resolveSrv()
'TXT'This type of record contains an array property called entries which refers to dns.resolveTxt(), e.g. { entries: ['...'], type: 'TXT' }
\n

Here is an example of the ret object passed to the callback:

\n\n
[ { type: 'A', address: '127.0.0.1', ttl: 299 },\n  { type: 'CNAME', value: 'example.com' },\n  { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },\n  { type: 'NS', value: 'ns1.example.com' },\n  { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },\n  { type: 'SOA',\n    nsname: 'ns1.example.com',\n    hostmaster: 'admin.example.com',\n    serial: 156696742,\n    refresh: 900,\n    retry: 900,\n    expire: 1800,\n    minttl: 60 } ]\n
\n

DNS server operators may choose not to respond to ANY\nqueries. It may be better to call individual methods like dns.resolve4(),\ndns.resolveMx(), and so on. For more details, see RFC 8482.

", "type": "module", "displayName": "`dns.resolveAny(hostname, callback)`" }, { "textRaw": "`dns.resolveCname(hostname, callback)`", "name": "`dns.resolvecname(hostname,_callback)`", "meta": { "added": [ "v0.3.2" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve CNAME records for the hostname. The\naddresses argument passed to the callback function\nwill contain an array of canonical name records available for the hostname\n(e.g. ['bar.example.com']).

", "type": "module", "displayName": "`dns.resolveCname(hostname, callback)`" }, { "textRaw": "`dns.resolveMx(hostname, callback)`", "name": "`dns.resolvemx(hostname,_callback)`", "meta": { "added": [ "v0.1.27" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve mail exchange records (MX records) for the\nhostname. The addresses argument passed to the callback function will\ncontain an array of objects containing both a priority and exchange\nproperty (e.g. [{priority: 10, exchange: 'mx.example.com'}, ...]).

", "type": "module", "displayName": "`dns.resolveMx(hostname, callback)`" }, { "textRaw": "`dns.resolveNaptr(hostname, callback)`", "name": "`dns.resolvenaptr(hostname,_callback)`", "meta": { "added": [ "v0.9.12" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve regular expression based records (NAPTR\nrecords) for the hostname. The addresses argument passed to the callback\nfunction will contain an array of objects with the following properties:

\n\n\n
{\n  flags: 's',\n  service: 'SIP+D2U',\n  regexp: '',\n  replacement: '_sip._udp.example.com',\n  order: 30,\n  preference: 100\n}\n
", "type": "module", "displayName": "`dns.resolveNaptr(hostname, callback)`" }, { "textRaw": "`dns.resolveNs(hostname, callback)`", "name": "`dns.resolvens(hostname,_callback)`", "meta": { "added": [ "v0.1.90" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve name server records (NS records) for the\nhostname. The addresses argument passed to the callback function will\ncontain an array of name server records available for hostname\n(e.g. ['ns1.example.com', 'ns2.example.com']).

", "type": "module", "displayName": "`dns.resolveNs(hostname, callback)`" }, { "textRaw": "`dns.resolvePtr(hostname, callback)`", "name": "`dns.resolveptr(hostname,_callback)`", "meta": { "added": [ "v6.0.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve pointer records (PTR records) for the\nhostname. The addresses argument passed to the callback function will\nbe an array of strings containing the reply records.

", "type": "module", "displayName": "`dns.resolvePtr(hostname, callback)`" }, { "textRaw": "`dns.resolveSoa(hostname, callback)`", "name": "`dns.resolvesoa(hostname,_callback)`", "meta": { "added": [ "v0.11.10" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve a start of authority record (SOA record) for\nthe hostname. The address argument passed to the callback function will\nbe an object with the following properties:

\n\n\n
{\n  nsname: 'ns.example.com',\n  hostmaster: 'root.example.com',\n  serial: 2013101809,\n  refresh: 10000,\n  retry: 2400,\n  expire: 604800,\n  minttl: 3600\n}\n
", "type": "module", "displayName": "`dns.resolveSoa(hostname, callback)`" }, { "textRaw": "`dns.resolveSrv(hostname, callback)`", "name": "`dns.resolvesrv(hostname,_callback)`", "meta": { "added": [ "v0.1.27" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve service records (SRV records) for the\nhostname. The addresses argument passed to the callback function will\nbe an array of objects with the following properties:

\n\n\n
{\n  priority: 10,\n  weight: 5,\n  port: 21223,\n  name: 'service.example.com'\n}\n
", "type": "module", "displayName": "`dns.resolveSrv(hostname, callback)`" }, { "textRaw": "`dns.resolveTxt(hostname, callback)`", "name": "`dns.resolvetxt(hostname,_callback)`", "meta": { "added": [ "v0.1.27" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve text queries (TXT records) for the\nhostname. The records argument passed to the callback function is a\ntwo-dimensional array of the text records available for hostname (e.g.\n[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]). Each sub-array contains TXT chunks of\none record. Depending on the use case, these could be either joined together or\ntreated separately.

", "type": "module", "displayName": "`dns.resolveTxt(hostname, callback)`" }, { "textRaw": "`dns.reverse(ip, callback)`", "name": "`dns.reverse(ip,_callback)`", "meta": { "added": [ "v0.1.16" ], "changes": [] }, "desc": "\n

Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an\narray of hostnames.

\n

On error, err is an Error object, where err.code is\none of the DNS error codes.

", "type": "module", "displayName": "`dns.reverse(ip, callback)`" }, { "textRaw": "`dns.setServers(servers)`", "name": "`dns.setservers(servers)`", "meta": { "added": [ "v0.11.3" ], "changes": [] }, "desc": "\n

Sets the IP address and port of servers to be used when performing DNS\nresolution. The servers argument is an array of rfc5952 formatted\naddresses. If the port is the IANA default DNS port (53) it can be omitted.

\n
dns.setServers([\n  '4.4.4.4',\n  '[2001:4860:4860::8888]',\n  '4.4.4.4:1053',\n  '[2001:4860:4860::8888]:1053'\n]);\n
\n

An error will be thrown if an invalid address is provided.

\n

The dns.setServers() method must not be called while a DNS query is in\nprogress.

\n

The dns.setServers() method affects only dns.resolve(),\n[dns.resolve*()][] and dns.reverse() (and specifically not\ndns.lookup()).

\n

Note that this method works much like\nresolve.conf.\nThat is, if attempting to resolve with the first server provided results in a\nNOTFOUND error, the resolve() method will not attempt to resolve with\nsubsequent servers provided. Fallback DNS servers will only be used if the\nearlier ones time out or result in some other error.

", "type": "module", "displayName": "`dns.setServers(servers)`" }, { "textRaw": "DNS Promises API", "name": "dns_promises_api", "stability": 2, "stabilityText": "Stable", "desc": "

The dns.promises API provides an alternative set of asynchronous DNS methods\nthat return Promise objects rather than using callbacks. The API is accessible\nvia require('dns').promises.

", "modules": [ { "textRaw": "Class: `dnsPromises.Resolver`", "name": "class:_`dnspromises.resolver`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "

An independent resolver for DNS requests.

\n

Note that creating a new resolver uses the default server settings. Setting\nthe servers used for a resolver using\nresolver.setServers() does not affect\nother resolvers:

\n
const { Resolver } = require('dns').promises;\nconst resolver = new Resolver();\nresolver.setServers(['4.4.4.4']);\n\n// This request will use the server at 4.4.4.4, independent of global settings.\nresolver.resolve4('example.org').then((addresses) => {\n  // ...\n});\n\n// Alternatively, the same code can be written using async-await style.\n(async function() {\n  const addresses = await resolver.resolve4('example.org');\n})();\n
\n

The following methods from the dnsPromises API are available:

\n", "type": "module", "displayName": "Class: `dnsPromises.Resolver`" }, { "textRaw": "`dnsPromises.getServers()`", "name": "`dnspromises.getservers()`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Returns an array of IP address strings, formatted according to rfc5952,\nthat are currently configured for DNS resolution. A string will include a port\nsection if a custom port is used.

\n\n
[\n  '4.4.4.4',\n  '2001:4860:4860::8888',\n  '4.4.4.4:1053',\n  '[2001:4860:4860::8888]:1053'\n]\n
", "type": "module", "displayName": "`dnsPromises.getServers()`" }, { "textRaw": "`dnsPromises.lookup(hostname[, options])`", "name": "`dnspromises.lookup(hostname[,_options])`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or\nAAAA (IPv6) record. All option properties are optional. If options is an\ninteger, then it must be 4 or 6 – if options is not provided, then IPv4\nand IPv6 addresses are both returned if found.

\n

With the all option set to true, the Promise is resolved with addresses\nbeing an array of objects with the properties address and family.

\n

On error, the Promise is rejected with an Error object, where err.code\nis the error code.\nKeep in mind that err.code will be set to 'ENOENT' not only when\nthe hostname does not exist but also when the lookup fails in other ways\nsuch as no available file descriptors.

\n

dnsPromises.lookup() does not necessarily have anything to do with the DNS\nprotocol. The implementation uses an operating system facility that can\nassociate names with addresses, and vice versa. This implementation can have\nsubtle but important consequences on the behavior of any Node.js program. Please\ntake some time to consult the Implementation considerations section before\nusing dnsPromises.lookup().

\n

Example usage:

\n
const dns = require('dns');\nconst dnsPromises = dns.promises;\nconst options = {\n  family: 6,\n  hints: dns.ADDRCONFIG | dns.V4MAPPED,\n};\n\ndnsPromises.lookup('example.com', options).then((result) => {\n  console.log('address: %j family: IPv%s', result.address, result.family);\n  // address: \"2606:2800:220:1:248:1893:25c8:1946\" family: IPv6\n});\n\n// When options.all is true, the result will be an Array.\noptions.all = true;\ndnsPromises.lookup('example.com', options).then((result) => {\n  console.log('addresses: %j', result);\n  // addresses: [{\"address\":\"2606:2800:220:1:248:1893:25c8:1946\",\"family\":6}]\n});\n
", "type": "module", "displayName": "`dnsPromises.lookup(hostname[, options])`" }, { "textRaw": "`dnsPromises.lookupService(address, port)`", "name": "`dnspromises.lookupservice(address,_port)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Resolves the given address and port into a hostname and service using\nthe operating system's underlying getnameinfo implementation.

\n

If address is not a valid IP address, a TypeError will be thrown.\nThe port will be coerced to a number. If it is not a legal port, a TypeError\nwill be thrown.

\n

On error, the Promise is rejected with an Error object, where err.code\nis the error code.

\n
const dnsPromises = require('dns').promises;\ndnsPromises.lookupService('127.0.0.1', 22).then((result) => {\n  console.log(result.hostname, result.service);\n  // Prints: localhost ssh\n});\n
", "type": "module", "displayName": "`dnsPromises.lookupService(address, port)`" }, { "textRaw": "`dnsPromises.resolve(hostname[, rrtype])`", "name": "`dnspromises.resolve(hostname[,_rrtype])`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array\nof the resource records. When successful, the Promise is resolved with an\narray of resource records. The type and structure of individual results vary\nbased on rrtype:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
rrtyperecords containsResult typeShorthand method
'A'IPv4 addresses (default)<string>dnsPromises.resolve4()
'AAAA'IPv6 addresses<string>dnsPromises.resolve6()
'ANY'any records<Object>dnsPromises.resolveAny()
'CNAME'canonical name records<string>dnsPromises.resolveCname()
'MX'mail exchange records<Object>dnsPromises.resolveMx()
'NAPTR'name authority pointer records<Object>dnsPromises.resolveNaptr()
'NS'name server records<string>dnsPromises.resolveNs()
'PTR'pointer records<string>dnsPromises.resolvePtr()
'SOA'start of authority records<Object>dnsPromises.resolveSoa()
'SRV'service records<Object>dnsPromises.resolveSrv()
'TXT'text records<string[]>dnsPromises.resolveTxt()
\n

On error, the Promise is rejected with an Error object, where err.code\nis one of the DNS error codes.

", "type": "module", "displayName": "`dnsPromises.resolve(hostname[, rrtype])`" }, { "textRaw": "`dnsPromises.resolve4(hostname[, options])`", "name": "`dnspromises.resolve4(hostname[,_options])`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve IPv4 addresses (A records) for the\nhostname. On success, the Promise is resolved with an array of IPv4\naddresses (e.g. ['74.125.79.104', '74.125.79.105', '74.125.79.106']).

", "type": "module", "displayName": "`dnsPromises.resolve4(hostname[, options])`" }, { "textRaw": "`dnsPromises.resolve6(hostname[, options])`", "name": "`dnspromises.resolve6(hostname[,_options])`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve IPv6 addresses (AAAA records) for the\nhostname. On success, the Promise is resolved with an array of IPv6\naddresses.

", "type": "module", "displayName": "`dnsPromises.resolve6(hostname[, options])`" }, { "textRaw": "`dnsPromises.resolveAny(hostname)`", "name": "`dnspromises.resolveany(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve all records (also known as ANY or * query).\nOn success, the Promise is resolved with an array containing various types of\nrecords. Each object has a property type that indicates the type of the\ncurrent record. And depending on the type, additional properties will be\npresent on the object:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
TypeProperties
'A'address/ttl
'AAAA'address/ttl
'CNAME'value
'MX'Refer to dnsPromises.resolveMx()
'NAPTR'Refer to dnsPromises.resolveNaptr()
'NS'value
'PTR'value
'SOA'Refer to dnsPromises.resolveSoa()
'SRV'Refer to dnsPromises.resolveSrv()
'TXT'This type of record contains an array property called entries which refers to dnsPromises.resolveTxt(), e.g. { entries: ['...'], type: 'TXT' }
\n

Here is an example of the result object:

\n\n
[ { type: 'A', address: '127.0.0.1', ttl: 299 },\n  { type: 'CNAME', value: 'example.com' },\n  { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },\n  { type: 'NS', value: 'ns1.example.com' },\n  { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },\n  { type: 'SOA',\n    nsname: 'ns1.example.com',\n    hostmaster: 'admin.example.com',\n    serial: 156696742,\n    refresh: 900,\n    retry: 900,\n    expire: 1800,\n    minttl: 60 } ]\n
", "type": "module", "displayName": "`dnsPromises.resolveAny(hostname)`" }, { "textRaw": "`dnsPromises.resolveCname(hostname)`", "name": "`dnspromises.resolvecname(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve CNAME records for the hostname. On success,\nthe Promise is resolved with an array of canonical name records available for\nthe hostname (e.g. ['bar.example.com']).

", "type": "module", "displayName": "`dnsPromises.resolveCname(hostname)`" }, { "textRaw": "`dnsPromises.resolveMx(hostname)`", "name": "`dnspromises.resolvemx(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve mail exchange records (MX records) for the\nhostname. On success, the Promise is resolved with an array of objects\ncontaining both a priority and exchange property (e.g.\n[{priority: 10, exchange: 'mx.example.com'}, ...]).

", "type": "module", "displayName": "`dnsPromises.resolveMx(hostname)`" }, { "textRaw": "`dnsPromises.resolveNaptr(hostname)`", "name": "`dnspromises.resolvenaptr(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve regular expression based records (NAPTR\nrecords) for the hostname. On success, the Promise is resolved with an array\nof objects with the following properties:

\n\n\n
{\n  flags: 's',\n  service: 'SIP+D2U',\n  regexp: '',\n  replacement: '_sip._udp.example.com',\n  order: 30,\n  preference: 100\n}\n
", "type": "module", "displayName": "`dnsPromises.resolveNaptr(hostname)`" }, { "textRaw": "`dnsPromises.resolveNs(hostname)`", "name": "`dnspromises.resolvens(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve name server records (NS records) for the\nhostname. On success, the Promise is resolved with an array of name server\nrecords available for hostname (e.g.\n['ns1.example.com', 'ns2.example.com']).

", "type": "module", "displayName": "`dnsPromises.resolveNs(hostname)`" }, { "textRaw": "`dnsPromises.resolvePtr(hostname)`", "name": "`dnspromises.resolveptr(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve pointer records (PTR records) for the\nhostname. On success, the Promise is resolved with an array of strings\ncontaining the reply records.

", "type": "module", "displayName": "`dnsPromises.resolvePtr(hostname)`" }, { "textRaw": "`dnsPromises.resolveSoa(hostname)`", "name": "`dnspromises.resolvesoa(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve a start of authority record (SOA record) for\nthe hostname. On success, the Promise is resolved with an object with the\nfollowing properties:

\n\n\n
{\n  nsname: 'ns.example.com',\n  hostmaster: 'root.example.com',\n  serial: 2013101809,\n  refresh: 10000,\n  retry: 2400,\n  expire: 604800,\n  minttl: 3600\n}\n
", "type": "module", "displayName": "`dnsPromises.resolveSoa(hostname)`" }, { "textRaw": "`dnsPromises.resolveSrv(hostname)`", "name": "`dnspromises.resolvesrv(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve service records (SRV records) for the\nhostname. On success, the Promise is resolved with an array of objects with\nthe following properties:

\n\n\n
{\n  priority: 10,\n  weight: 5,\n  port: 21223,\n  name: 'service.example.com'\n}\n
", "type": "module", "displayName": "`dnsPromises.resolveSrv(hostname)`" }, { "textRaw": "`dnsPromises.resolveTxt(hostname)`", "name": "`dnspromises.resolvetxt(hostname)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Uses the DNS protocol to resolve text queries (TXT records) for the\nhostname. On success, the Promise is resolved with a two-dimensional array\nof the text records available for hostname (e.g.\n[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]). Each sub-array contains TXT chunks of\none record. Depending on the use case, these could be either joined together or\ntreated separately.

", "type": "module", "displayName": "`dnsPromises.resolveTxt(hostname)`" }, { "textRaw": "`dnsPromises.reverse(ip)`", "name": "`dnspromises.reverse(ip)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an\narray of hostnames.

\n

On error, the Promise is rejected with an Error object, where err.code\nis one of the DNS error codes.

", "type": "module", "displayName": "`dnsPromises.reverse(ip)`" }, { "textRaw": "`dnsPromises.setServers(servers)`", "name": "`dnspromises.setservers(servers)`", "meta": { "added": [ "v10.6.0" ], "changes": [] }, "desc": "\n

Sets the IP address and port of servers to be used when performing DNS\nresolution. The servers argument is an array of rfc5952 formatted\naddresses. If the port is the IANA default DNS port (53) it can be omitted.

\n
dnsPromises.setServers([\n  '4.4.4.4',\n  '[2001:4860:4860::8888]',\n  '4.4.4.4:1053',\n  '[2001:4860:4860::8888]:1053'\n]);\n
\n

An error will be thrown if an invalid address is provided.

\n

The dnsPromises.setServers() method must not be called while a DNS query is in\nprogress.

\n

Note that this method works much like\nresolve.conf.\nThat is, if attempting to resolve with the first server provided results in a\nNOTFOUND error, the resolve() method will not attempt to resolve with\nsubsequent servers provided. Fallback DNS servers will only be used if the\nearlier ones time out or result in some other error.

", "type": "module", "displayName": "`dnsPromises.setServers(servers)`" } ], "type": "module", "displayName": "DNS Promises API" }, { "textRaw": "Error codes", "name": "error_codes", "desc": "

Each DNS query can return one of the following error codes:

\n", "type": "module", "displayName": "Error codes" }, { "textRaw": "Implementation considerations", "name": "implementation_considerations", "desc": "

Although dns.lookup() and the various dns.resolve*()/dns.reverse()\nfunctions have the same goal of associating a network name with a network\naddress (or vice versa), their behavior is quite different. These differences\ncan have subtle but significant consequences on the behavior of Node.js\nprograms.

", "modules": [ { "textRaw": "`dns.lookup()`", "name": "`dns.lookup()`", "desc": "

Under the hood, dns.lookup() uses the same operating system facilities\nas most other programs. For instance, dns.lookup() will almost always\nresolve a given name the same way as the ping command. On most POSIX-like\noperating systems, the behavior of the dns.lookup() function can be\nmodified by changing settings in nsswitch.conf(5) and/or resolv.conf(5),\nbut note that changing these files will change the behavior of all other\nprograms running on the same operating system.

\n

Though the call to dns.lookup() will be asynchronous from JavaScript's\nperspective, it is implemented as a synchronous call to getaddrinfo(3) that runs\non libuv's threadpool. This can have surprising negative performance\nimplications for some applications, see the UV_THREADPOOL_SIZE\ndocumentation for more information.

\n

Note that various networking APIs will call dns.lookup() internally to resolve\nhost names. If that is an issue, consider resolving the hostname to an address\nusing dns.resolve() and using the address instead of a host name. Also, some\nnetworking APIs (such as socket.connect() and dgram.createSocket())\nallow the default resolver, dns.lookup(), to be replaced.

", "type": "module", "displayName": "`dns.lookup()`" }, { "textRaw": "`dns.resolve()`, `dns.resolve*()` and `dns.reverse()`", "name": "`dns.resolve()`,_`dns.resolve*()`_and_`dns.reverse()`", "desc": "

These functions are implemented quite differently than dns.lookup(). They\ndo not use getaddrinfo(3) and they always perform a DNS query on the\nnetwork. This network communication is always done asynchronously, and does not\nuse libuv's threadpool.

\n

As a result, these functions cannot have the same negative impact on other\nprocessing that happens on libuv's threadpool that dns.lookup() can have.

\n

They do not use the same set of configuration files than what dns.lookup()\nuses. For instance, they do not use the configuration from /etc/hosts.

", "type": "module", "displayName": "`dns.resolve()`, `dns.resolve*()` and `dns.reverse()`" } ], "type": "module", "displayName": "Implementation considerations" } ], "type": "module", "displayName": "DNS" } ] }