nodejs-mozilla/doc/api/dns.json

1348 lines
88 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"type": "module",
"source": "doc/api/dns.md",
"modules": [
{
"textRaw": "DNS",
"name": "dns",
"introduced_in": "v0.10.0",
"stability": 2,
"stabilityText": "Stable",
"desc": "<p>The <code>dns</code> module enables name resolution. For example, use it to look up IP\naddresses of host names.</p>\n<p>Although named for the <a href=\"https://en.wikipedia.org/wiki/Domain_Name_System\">Domain Name System (DNS)</a>, it does not always use the\nDNS protocol for lookups. <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> uses the operating system\nfacilities to perform name resolution. It may not need to perform any network\ncommunication. Developers looking to perform name resolution in the same way\nthat other applications on the same operating system behave should use\n<a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a>.</p>\n<pre><code class=\"language-js\">const dns = require('dns');\n\ndns.lookup('example.org', (err, address, family) => {\n console.log('address: %j family: IPv%s', address, family);\n});\n// address: \"93.184.216.34\" family: IPv4\n</code></pre>\n<p>All other functions in the <code>dns</code> module connect to an actual DNS server to\nperform name resolution. They will always use the network to perform DNS\nqueries. These functions do not use the same set of configuration files used by\n<a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> (e.g. <code>/etc/hosts</code>). These functions should be used by\ndevelopers who do not want to use the underlying operating system's\nfacilities for name resolution, and instead want to always perform DNS queries.</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>See the <a href=\"#dns_implementation_considerations\">Implementation considerations section</a> for more information.</p>",
"classes": [
{
"textRaw": "Class: `dns.Resolver`",
"type": "class",
"name": "dns.Resolver",
"meta": {
"added": [
"v8.3.0"
],
"changes": []
},
"desc": "<p>An independent resolver for DNS requests.</p>\n<p>Creating a new resolver uses the default server settings. Setting\nthe servers used for a resolver using\n<a href=\"#dns_dns_setservers_servers\"><code>resolver.setServers()</code></a> does not affect\nother resolvers:</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>The following methods from the <code>dns</code> module are available:</p>\n<ul>\n<li><a href=\"#dns_dns_getservers\"><code>resolver.getServers()</code></a></li>\n<li><a href=\"#dns_dns_resolve_hostname_rrtype_callback\"><code>resolver.resolve()</code></a></li>\n<li><a href=\"#dns_dns_resolve4_hostname_options_callback\"><code>resolver.resolve4()</code></a></li>\n<li><a href=\"#dns_dns_resolve6_hostname_options_callback\"><code>resolver.resolve6()</code></a></li>\n<li><a href=\"#dns_dns_resolveany_hostname_callback\"><code>resolver.resolveAny()</code></a></li>\n<li><a href=\"#dns_dns_resolvecname_hostname_callback\"><code>resolver.resolveCname()</code></a></li>\n<li><a href=\"#dns_dns_resolvemx_hostname_callback\"><code>resolver.resolveMx()</code></a></li>\n<li><a href=\"#dns_dns_resolvenaptr_hostname_callback\"><code>resolver.resolveNaptr()</code></a></li>\n<li><a href=\"#dns_dns_resolvens_hostname_callback\"><code>resolver.resolveNs()</code></a></li>\n<li><a href=\"#dns_dns_resolveptr_hostname_callback\"><code>resolver.resolvePtr()</code></a></li>\n<li><a href=\"#dns_dns_resolvesoa_hostname_callback\"><code>resolver.resolveSoa()</code></a></li>\n<li><a href=\"#dns_dns_resolvesrv_hostname_callback\"><code>resolver.resolveSrv()</code></a></li>\n<li><a href=\"#dns_dns_resolvetxt_hostname_callback\"><code>resolver.resolveTxt()</code></a></li>\n<li><a href=\"#dns_dns_reverse_ip_callback\"><code>resolver.reverse()</code></a></li>\n<li><a href=\"#dns_dns_setservers_servers\"><code>resolver.setServers()</code></a></li>\n</ul>",
"methods": [
{
"textRaw": "`resolver.cancel()`",
"type": "method",
"name": "cancel",
"meta": {
"added": [
"v8.3.0"
],
"changes": []
},
"signatures": [
{
"params": []
}
],
"desc": "<p>Cancel all outstanding DNS queries made by this resolver. The corresponding\ncallbacks will be called with an error with code <code>ECANCELLED</code>.</p>"
}
]
}
],
"methods": [
{
"textRaw": "`dns.getServers()`",
"type": "method",
"name": "getServers",
"meta": {
"added": [
"v0.11.3"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string[]}",
"name": "return",
"type": "string[]"
},
"params": []
}
],
"desc": "<p>Returns an array of IP address strings, formatted according to <a href=\"https://tools.ietf.org/html/rfc5952#section-6\">RFC 5952</a>,\nthat are currently configured for DNS resolution. A string will include a port\nsection if a custom port is used.</p>\n<!-- eslint-disable semi-->\n<pre><code class=\"language-js\">[\n '4.4.4.4',\n '2001:4860:4860::8888',\n '4.4.4.4:1053',\n '[2001:4860:4860::8888]:1053'\n]\n</code></pre>"
},
{
"textRaw": "`dns.lookup(hostname[, options], callback)`",
"type": "method",
"name": "lookup",
"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."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`options` {integer | Object}",
"name": "options",
"type": "integer | Object",
"options": [
{
"textRaw": "`family` {integer} The record family. Must be `4`, `6`, or `0`. The value `0` indicates that IPv4 and IPv6 addresses are both returned. **Default:** `0`.",
"name": "family",
"type": "integer",
"default": "`0`",
"desc": "The record family. Must be `4`, `6`, or `0`. The value `0` indicates that IPv4 and IPv6 addresses are both returned."
},
{
"textRaw": "`hints` {number} One or more [supported `getaddrinfo` flags][]. Multiple flags may be passed by bitwise `OR`ing their values.",
"name": "hints",
"type": "number",
"desc": "One or more [supported `getaddrinfo` flags][]. Multiple flags may be passed by bitwise `OR`ing their values."
},
{
"textRaw": "`all` {boolean} When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address. **Default:** `false`.",
"name": "all",
"type": "boolean",
"default": "`false`",
"desc": "When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address."
},
{
"textRaw": "`verbatim` {boolean} When `true`, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4 addresses are placed before IPv6 addresses. **Default:** currently `false` (addresses are reordered) but this is expected to change in the not too distant future. New code should use `{ verbatim: true }`.",
"name": "verbatim",
"type": "boolean",
"default": "currently `false` (addresses are reordered) but this is expected to change in the not too distant future. New code should use `{ verbatim: true }`",
"desc": "When `true`, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4 addresses are placed before IPv6 addresses."
}
]
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`address` {string} A string representation of an IPv4 or IPv6 address.",
"name": "address",
"type": "string",
"desc": "A string representation of an IPv4 or IPv6 address."
},
{
"textRaw": "`family` {integer} `4` or `6`, denoting the family of `address`, or `0` if the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a bug in the name resolution service used by the operating system.",
"name": "family",
"type": "integer",
"desc": "`4` or `6`, denoting the family of `address`, or `0` if the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a bug in the name resolution service used by the operating system."
}
]
}
]
}
],
"desc": "<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or\nAAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an\ninteger, then it must be <code>4</code> or <code>6</code> if <code>options</code> is not provided, then IPv4\nand IPv6 addresses are both returned if found.</p>\n<p>With the <code>all</code> option set to <code>true</code>, the arguments for <code>callback</code> change to\n<code>(err, addresses)</code>, with <code>addresses</code> being an array of objects with the\nproperties <code>address</code> and <code>family</code>.</p>\n<p>On error, <code>err</code> is an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code> is the error code.\nKeep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when\nthe host name does not exist but also when the lookup fails in other ways\nsuch as no available file descriptors.</p>\n<p><code>dns.lookup()</code> 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 <a href=\"#dns_implementation_considerations\">Implementation considerations section</a> before using\n<code>dns.lookup()</code>.</p>\n<p>Example usage:</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>If this method is invoked as its <a href=\"util.html#util_util_promisify_original\"><code>util.promisify()</code></a>ed version, and <code>all</code>\nis not set to <code>true</code>, it returns a <code>Promise</code> for an <code>Object</code> with <code>address</code> and\n<code>family</code> properties.</p>",
"modules": [
{
"textRaw": "Supported getaddrinfo flags",
"name": "supported_getaddrinfo_flags",
"meta": {
"changes": [
{
"version": "v12.17.0",
"pr-url": "https://github.com/nodejs/node/pull/32183",
"description": "Added support for the `dns.ALL` flag."
}
]
},
"desc": "<p>The following flags can be passed as hints to <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a>.</p>\n<ul>\n<li><code>dns.ADDRCONFIG</code>: Returned address types are determined by the types\nof addresses supported by the current system. For example, IPv4 addresses\nare only returned if the current system has at least one IPv4 address\nconfigured. Loopback addresses are not considered.</li>\n<li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses were\nfound, then return IPv4 mapped IPv6 addresses. It is not supported\non some operating systems (e.g FreeBSD 10.1).</li>\n<li><code>dns.ALL</code>: If <code>dns.V4MAPPED</code> is specified, return resolved IPv6 addresses as\nwell as IPv4 mapped IPv6 addresses.</li>\n</ul>",
"type": "module",
"displayName": "Supported getaddrinfo flags"
}
]
},
{
"textRaw": "`dns.lookupService(address, port, callback)`",
"type": "method",
"name": "lookupService",
"meta": {
"added": [
"v0.11.14"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`address` {string}",
"name": "address",
"type": "string"
},
{
"textRaw": "`port` {number}",
"name": "port",
"type": "number"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`hostname` {string} e.g. `example.com`",
"name": "hostname",
"type": "string",
"desc": "e.g. `example.com`"
},
{
"textRaw": "`service` {string} e.g. `http`",
"name": "service",
"type": "string",
"desc": "e.g. `http`"
}
]
}
]
}
],
"desc": "<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using\nthe operating system's underlying <code>getnameinfo</code> implementation.</p>\n<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.\nThe <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>\nwill be thrown.</p>\n<p>On an error, <code>err</code> is an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code> is the error code.</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>If this method is invoked as its <a href=\"util.html#util_util_promisify_original\"><code>util.promisify()</code></a>ed version, it returns a\n<code>Promise</code> for an <code>Object</code> with <code>hostname</code> and <code>service</code> properties.</p>"
},
{
"textRaw": "`dns.resolve(hostname[, rrtype], callback)`",
"type": "method",
"name": "resolve",
"meta": {
"added": [
"v0.1.27"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string} Host name to resolve.",
"name": "hostname",
"type": "string",
"desc": "Host name to resolve."
},
{
"textRaw": "`rrtype` {string} Resource record type. **Default:** `'A'`.",
"name": "rrtype",
"type": "string",
"default": "`'A'`",
"desc": "Resource record type."
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`records` {string[] | Object[] | Object}",
"name": "records",
"type": "string[] | Object[] | Object"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array\nof the resource records. The <code>callback</code> function has arguments\n<code>(err, records)</code>. When successful, <code>records</code> will be an array of resource\nrecords. The type and structure of individual results varies based on <code>rrtype</code>:</p>\n<table>\n<thead>\n<tr>\n<th><code>rrtype</code></th>\n<th><code>records</code> contains</th>\n<th>Result type</th>\n<th>Shorthand method</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'A'</code></td>\n<td>IPv4 addresses (default)</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dns_resolve4_hostname_options_callback\"><code>dns.resolve4()</code></a></td>\n</tr>\n<tr>\n<td><code>'AAAA'</code></td>\n<td>IPv6 addresses</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dns_resolve6_hostname_options_callback\"><code>dns.resolve6()</code></a></td>\n</tr>\n<tr>\n<td><code>'ANY'</code></td>\n<td>any records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dns_resolveany_hostname_callback\"><code>dns.resolveAny()</code></a></td>\n</tr>\n<tr>\n<td><code>'CNAME'</code></td>\n<td>canonical name records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dns_resolvecname_hostname_callback\"><code>dns.resolveCname()</code></a></td>\n</tr>\n<tr>\n<td><code>'MX'</code></td>\n<td>mail exchange records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dns_resolvemx_hostname_callback\"><code>dns.resolveMx()</code></a></td>\n</tr>\n<tr>\n<td><code>'NAPTR'</code></td>\n<td>name authority pointer records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dns_resolvenaptr_hostname_callback\"><code>dns.resolveNaptr()</code></a></td>\n</tr>\n<tr>\n<td><code>'NS'</code></td>\n<td>name server records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dns_resolvens_hostname_callback\"><code>dns.resolveNs()</code></a></td>\n</tr>\n<tr>\n<td><code>'PTR'</code></td>\n<td>pointer records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dns_resolveptr_hostname_callback\"><code>dns.resolvePtr()</code></a></td>\n</tr>\n<tr>\n<td><code>'SOA'</code></td>\n<td>start of authority records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dns_resolvesoa_hostname_callback\"><code>dns.resolveSoa()</code></a></td>\n</tr>\n<tr>\n<td><code>'SRV'</code></td>\n<td>service records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dns_resolvesrv_hostname_callback\"><code>dns.resolveSrv()</code></a></td>\n</tr>\n<tr>\n<td><code>'TXT'</code></td>\n<td>text records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[]&gt;</a></td>\n<td><a href=\"#dns_dns_resolvetxt_hostname_callback\"><code>dns.resolveTxt()</code></a></td>\n</tr>\n</tbody>\n</table>\n<p>On error, <code>err</code> is an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code> is one of the\n<a href=\"#dns_error_codes\">DNS error codes</a>.</p>"
},
{
"textRaw": "`dns.resolve4(hostname[, options], callback)`",
"type": "method",
"name": "resolve4",
"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`."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string} Host name to resolve.",
"name": "hostname",
"type": "string",
"desc": "Host name to resolve."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record. When `true`, the callback receives an array of `{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds.",
"name": "ttl",
"type": "boolean",
"desc": "Retrieve the Time-To-Live value (TTL) of each record. When `true`, the callback receives an array of `{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds."
}
]
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {string[] | Object[]}",
"name": "addresses",
"type": "string[] | Object[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve a IPv4 addresses (<code>A</code> records) for the\n<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function\nwill contain an array of IPv4 addresses (e.g.\n<code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>"
},
{
"textRaw": "`dns.resolve6(hostname[, options], callback)`",
"type": "method",
"name": "resolve6",
"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`."
}
]
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string} Host name to resolve.",
"name": "hostname",
"type": "string",
"desc": "Host name to resolve."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record. When `true`, the callback receives an array of `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds.",
"name": "ttl",
"type": "boolean",
"desc": "Retrieve the Time-To-Live value (TTL) of each record. When `true`, the callback receives an array of `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds."
}
]
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {string[] | Object[]}",
"name": "addresses",
"type": "string[] | Object[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve a IPv6 addresses (<code>AAAA</code> records) for the\n<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function\nwill contain an array of IPv6 addresses.</p>"
},
{
"textRaw": "`dns.resolveAny(hostname, callback)`",
"type": "method",
"name": "resolveAny",
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`ret` {Object[]}",
"name": "ret",
"type": "Object[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).\nThe <code>ret</code> argument passed to the <code>callback</code> function will be an array containing\nvarious types of records. Each object has a property <code>type</code> that indicates the\ntype of the current record. And depending on the <code>type</code>, additional properties\nwill be present on the object:</p>\n<table>\n<thead>\n<tr>\n<th>Type</th>\n<th>Properties</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'A'</code></td>\n<td><code>address</code>/<code>ttl</code></td>\n</tr>\n<tr>\n<td><code>'AAAA'</code></td>\n<td><code>address</code>/<code>ttl</code></td>\n</tr>\n<tr>\n<td><code>'CNAME'</code></td>\n<td><code>value</code></td>\n</tr>\n<tr>\n<td><code>'MX'</code></td>\n<td>Refer to <a href=\"#dns_dns_resolvemx_hostname_callback\"><code>dns.resolveMx()</code></a></td>\n</tr>\n<tr>\n<td><code>'NAPTR'</code></td>\n<td>Refer to <a href=\"#dns_dns_resolvenaptr_hostname_callback\"><code>dns.resolveNaptr()</code></a></td>\n</tr>\n<tr>\n<td><code>'NS'</code></td>\n<td><code>value</code></td>\n</tr>\n<tr>\n<td><code>'PTR'</code></td>\n<td><code>value</code></td>\n</tr>\n<tr>\n<td><code>'SOA'</code></td>\n<td>Refer to <a href=\"#dns_dns_resolvesoa_hostname_callback\"><code>dns.resolveSoa()</code></a></td>\n</tr>\n<tr>\n<td><code>'SRV'</code></td>\n<td>Refer to <a href=\"#dns_dns_resolvesrv_hostname_callback\"><code>dns.resolveSrv()</code></a></td>\n</tr>\n<tr>\n<td><code>'TXT'</code></td>\n<td>This type of record contains an array property called <code>entries</code> which refers to <a href=\"#dns_dns_resolvetxt_hostname_callback\"><code>dns.resolveTxt()</code></a>, e.g. <code>{ entries: ['...'], type: 'TXT' }</code></td>\n</tr>\n</tbody>\n</table>\n<p>Here is an example of the <code>ret</code> object passed to the callback:</p>\n<!-- eslint-disable semi -->\n<pre><code class=\"language-js\">[ { 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</code></pre>\n<p>DNS server operators may choose not to respond to <code>ANY</code>\nqueries. It may be better to call individual methods like <a href=\"#dns_dns_resolve4_hostname_options_callback\"><code>dns.resolve4()</code></a>,\n<a href=\"#dns_dns_resolvemx_hostname_callback\"><code>dns.resolveMx()</code></a>, and so on. For more details, see <a href=\"https://tools.ietf.org/html/rfc8482\">RFC 8482</a>.</p>"
},
{
"textRaw": "`dns.resolveCname(hostname, callback)`",
"type": "method",
"name": "resolveCname",
"meta": {
"added": [
"v0.3.2"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {string[]}",
"name": "addresses",
"type": "string[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. The\n<code>addresses</code> argument passed to the <code>callback</code> function\nwill contain an array of canonical name records available for the <code>hostname</code>\n(e.g. <code>['bar.example.com']</code>).</p>"
},
{
"textRaw": "`dns.resolveMx(hostname, callback)`",
"type": "method",
"name": "resolveMx",
"meta": {
"added": [
"v0.1.27"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {Object[]}",
"name": "addresses",
"type": "Object[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the\n<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will\ncontain an array of objects containing both a <code>priority</code> and <code>exchange</code>\nproperty (e.g. <code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>"
},
{
"textRaw": "`dns.resolveNaptr(hostname, callback)`",
"type": "method",
"name": "resolveNaptr",
"meta": {
"added": [
"v0.9.12"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {Object[]}",
"name": "addresses",
"type": "Object[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve regular expression based records (<code>NAPTR</code>\nrecords) for the <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code>\nfunction will contain an array of objects with the following properties:</p>\n<ul>\n<li><code>flags</code></li>\n<li><code>service</code></li>\n<li><code>regexp</code></li>\n<li><code>replacement</code></li>\n<li><code>order</code></li>\n<li><code>preference</code></li>\n</ul>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\n flags: 's',\n service: 'SIP+D2U',\n regexp: '',\n replacement: '_sip._udp.example.com',\n order: 30,\n preference: 100\n}\n</code></pre>"
},
{
"textRaw": "`dns.resolveNs(hostname, callback)`",
"type": "method",
"name": "resolveNs",
"meta": {
"added": [
"v0.1.90"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {string[]}",
"name": "addresses",
"type": "string[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the\n<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will\ncontain an array of name server records available for <code>hostname</code>\n(e.g. <code>['ns1.example.com', 'ns2.example.com']</code>).</p>"
},
{
"textRaw": "`dns.resolvePtr(hostname, callback)`",
"type": "method",
"name": "resolvePtr",
"meta": {
"added": [
"v6.0.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {string[]}",
"name": "addresses",
"type": "string[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the\n<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will\nbe an array of strings containing the reply records.</p>"
},
{
"textRaw": "`dns.resolveSoa(hostname, callback)`",
"type": "method",
"name": "resolveSoa",
"meta": {
"added": [
"v0.11.10"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`address` {Object}",
"name": "address",
"type": "Object"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for\nthe <code>hostname</code>. The <code>address</code> argument passed to the <code>callback</code> function will\nbe an object with the following properties:</p>\n<ul>\n<li><code>nsname</code></li>\n<li><code>hostmaster</code></li>\n<li><code>serial</code></li>\n<li><code>refresh</code></li>\n<li><code>retry</code></li>\n<li><code>expire</code></li>\n<li><code>minttl</code></li>\n</ul>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\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</code></pre>"
},
{
"textRaw": "`dns.resolveSrv(hostname, callback)`",
"type": "method",
"name": "resolveSrv",
"meta": {
"added": [
"v0.1.27"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`addresses` {Object[]}",
"name": "addresses",
"type": "Object[]"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the\n<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will\nbe an array of objects with the following properties:</p>\n<ul>\n<li><code>priority</code></li>\n<li><code>weight</code></li>\n<li><code>port</code></li>\n<li><code>name</code></li>\n</ul>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\n priority: 10,\n weight: 5,\n port: 21223,\n name: 'service.example.com'\n}\n</code></pre>"
},
{
"textRaw": "`dns.resolveTxt(hostname, callback)`",
"type": "method",
"name": "resolveTxt",
"meta": {
"added": [
"v0.1.27"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`records` <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[][]&gt;</a>",
"name": "records",
"desc": "<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[][]&gt;</a>"
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the\n<code>hostname</code>. The <code>records</code> argument passed to the <code>callback</code> function is a\ntwo-dimensional array of the text records available for <code>hostname</code> (e.g.\n<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of\none record. Depending on the use case, these could be either joined together or\ntreated separately.</p>"
},
{
"textRaw": "`dns.reverse(ip, callback)`",
"type": "method",
"name": "reverse",
"meta": {
"added": [
"v0.1.16"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`ip` {string}",
"name": "ip",
"type": "string"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function",
"options": [
{
"textRaw": "`err` {Error}",
"name": "err",
"type": "Error"
},
{
"textRaw": "`hostnames` {string[]}",
"name": "hostnames",
"type": "string[]"
}
]
}
]
}
],
"desc": "<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an\narray of host names.</p>\n<p>On error, <code>err</code> is an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code> is\none of the <a href=\"#dns_error_codes\">DNS error codes</a>.</p>"
},
{
"textRaw": "`dns.setServers(servers)`",
"type": "method",
"name": "setServers",
"meta": {
"added": [
"v0.11.3"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`servers` {string[]} array of [RFC 5952][] formatted addresses",
"name": "servers",
"type": "string[]",
"desc": "array of [RFC 5952][] formatted addresses"
}
]
}
],
"desc": "<p>Sets the IP address and port of servers to be used when performing DNS\nresolution. The <code>servers</code> argument is an array of <a href=\"https://tools.ietf.org/html/rfc5952#section-6\">RFC 5952</a> formatted\naddresses. If the port is the IANA default DNS port (53) it can be omitted.</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>An error will be thrown if an invalid address is provided.</p>\n<p>The <code>dns.setServers()</code> method must not be called while a DNS query is in\nprogress.</p>\n<p>The <a href=\"#dns_dns_setservers_servers\"><code>dns.setServers()</code></a> method affects only <a href=\"#dns_dns_resolve_hostname_rrtype_callback\"><code>dns.resolve()</code></a>,\n<code>dns.resolve*()</code> and <a href=\"#dns_dns_reverse_ip_callback\"><code>dns.reverse()</code></a> (and specifically <em>not</em>\n<a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a>).</p>\n<p>This method works much like\n<a href=\"http://man7.org/linux/man-pages/man5/resolv.conf.5.html\">resolve.conf</a>.\nThat is, if attempting to resolve with the first server provided results in a\n<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> 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.</p>"
}
],
"modules": [
{
"textRaw": "DNS Promises API",
"name": "dns_promises_api",
"desc": "<p>The <code>dns.promises</code> API provides an alternative set of asynchronous DNS methods\nthat return <code>Promise</code> objects rather than using callbacks. The API is accessible\nvia <code>require('dns').promises</code>.</p>",
"classes": [
{
"textRaw": "Class: `dnsPromises.Resolver`",
"type": "class",
"name": "dnsPromises.Resolver",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"desc": "<p>An independent resolver for DNS requests.</p>\n<p>Creating a new resolver uses the default server settings. Setting\nthe servers used for a resolver using\n<a href=\"#dns_dnspromises_setservers_servers\"><code>resolver.setServers()</code></a> does not affect\nother resolvers:</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>The following methods from the <code>dnsPromises</code> API are available:</p>\n<ul>\n<li><a href=\"#dns_dnspromises_getservers\"><code>resolver.getServers()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolve_hostname_rrtype\"><code>resolver.resolve()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolve4_hostname_options\"><code>resolver.resolve4()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolve6_hostname_options\"><code>resolver.resolve6()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolveany_hostname\"><code>resolver.resolveAny()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvecname_hostname\"><code>resolver.resolveCname()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvemx_hostname\"><code>resolver.resolveMx()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvenaptr_hostname\"><code>resolver.resolveNaptr()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvens_hostname\"><code>resolver.resolveNs()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolveptr_hostname\"><code>resolver.resolvePtr()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvesoa_hostname\"><code>resolver.resolveSoa()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvesrv_hostname\"><code>resolver.resolveSrv()</code></a></li>\n<li><a href=\"#dns_dnspromises_resolvetxt_hostname\"><code>resolver.resolveTxt()</code></a></li>\n<li><a href=\"#dns_dnspromises_reverse_ip\"><code>resolver.reverse()</code></a></li>\n<li><a href=\"#dns_dnspromises_setservers_servers\"><code>resolver.setServers()</code></a></li>\n</ul>"
}
],
"methods": [
{
"textRaw": "`dnsPromises.getServers()`",
"type": "method",
"name": "getServers",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string[]}",
"name": "return",
"type": "string[]"
},
"params": []
}
],
"desc": "<p>Returns an array of IP address strings, formatted according to <a href=\"https://tools.ietf.org/html/rfc5952#section-6\">RFC 5952</a>,\nthat are currently configured for DNS resolution. A string will include a port\nsection if a custom port is used.</p>\n<!-- eslint-disable semi-->\n<pre><code class=\"language-js\">[\n '4.4.4.4',\n '2001:4860:4860::8888',\n '4.4.4.4:1053',\n '[2001:4860:4860::8888]:1053'\n]\n</code></pre>"
},
{
"textRaw": "`dnsPromises.lookup(hostname[, options])`",
"type": "method",
"name": "lookup",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
},
{
"textRaw": "`options` {integer | Object}",
"name": "options",
"type": "integer | Object",
"options": [
{
"textRaw": "`family` {integer} The record family. Must be `4`, `6`, or `0`. The value `0` indicates that IPv4 and IPv6 addresses are both returned. **Default:** `0`.",
"name": "family",
"type": "integer",
"default": "`0`",
"desc": "The record family. Must be `4`, `6`, or `0`. The value `0` indicates that IPv4 and IPv6 addresses are both returned."
},
{
"textRaw": "`hints` {number} One or more [supported `getaddrinfo` flags][]. Multiple flags may be passed by bitwise `OR`ing their values.",
"name": "hints",
"type": "number",
"desc": "One or more [supported `getaddrinfo` flags][]. Multiple flags may be passed by bitwise `OR`ing their values."
},
{
"textRaw": "`all` {boolean} When `true`, the `Promise` is resolved with all addresses in an array. Otherwise, returns a single address. **Default:** `false`.",
"name": "all",
"type": "boolean",
"default": "`false`",
"desc": "When `true`, the `Promise` is resolved with all addresses in an array. Otherwise, returns a single address."
},
{
"textRaw": "`verbatim` {boolean} When `true`, the `Promise` is resolved with IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4 addresses are placed before IPv6 addresses. **Default:** currently `false` (addresses are reordered) but this is expected to change in the not too distant future. New code should use `{ verbatim: true }`.",
"name": "verbatim",
"type": "boolean",
"default": "currently `false` (addresses are reordered) but this is expected to change in the not too distant future. New code should use `{ verbatim: true }`",
"desc": "When `true`, the `Promise` is resolved with IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4 addresses are placed before IPv6 addresses."
}
]
}
]
}
],
"desc": "<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or\nAAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an\ninteger, then it must be <code>4</code> or <code>6</code> if <code>options</code> is not provided, then IPv4\nand IPv6 addresses are both returned if found.</p>\n<p>With the <code>all</code> option set to <code>true</code>, the <code>Promise</code> is resolved with <code>addresses</code>\nbeing an array of objects with the properties <code>address</code> and <code>family</code>.</p>\n<p>On error, the <code>Promise</code> is rejected with an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code>\nis the error code.\nKeep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when\nthe host name does not exist but also when the lookup fails in other ways\nsuch as no available file descriptors.</p>\n<p><a href=\"#dns_dnspromises_lookup_hostname_options\"><code>dnsPromises.lookup()</code></a> 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 <a href=\"#dns_implementation_considerations\">Implementation considerations section</a> before\nusing <code>dnsPromises.lookup()</code>.</p>\n<p>Example usage:</p>\n<pre><code class=\"language-js\">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</code></pre>"
},
{
"textRaw": "`dnsPromises.lookupService(address, port)`",
"type": "method",
"name": "lookupService",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`address` {string}",
"name": "address",
"type": "string"
},
{
"textRaw": "`port` {number}",
"name": "port",
"type": "number"
}
]
}
],
"desc": "<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using\nthe operating system's underlying <code>getnameinfo</code> implementation.</p>\n<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.\nThe <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>\nwill be thrown.</p>\n<p>On error, the <code>Promise</code> is rejected with an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code>\nis the error code.</p>\n<pre><code class=\"language-js\">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</code></pre>"
},
{
"textRaw": "`dnsPromises.resolve(hostname[, rrtype])`",
"type": "method",
"name": "resolve",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string} Host name to resolve.",
"name": "hostname",
"type": "string",
"desc": "Host name to resolve."
},
{
"textRaw": "`rrtype` {string} Resource record type. **Default:** `'A'`.",
"name": "rrtype",
"type": "string",
"default": "`'A'`",
"desc": "Resource record type."
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array\nof the resource records. When successful, the <code>Promise</code> is resolved with an\narray of resource records. The type and structure of individual results vary\nbased on <code>rrtype</code>:</p>\n<table>\n<thead>\n<tr>\n<th><code>rrtype</code></th>\n<th><code>records</code> contains</th>\n<th>Result type</th>\n<th>Shorthand method</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'A'</code></td>\n<td>IPv4 addresses (default)</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolve4_hostname_options\"><code>dnsPromises.resolve4()</code></a></td>\n</tr>\n<tr>\n<td><code>'AAAA'</code></td>\n<td>IPv6 addresses</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolve6_hostname_options\"><code>dnsPromises.resolve6()</code></a></td>\n</tr>\n<tr>\n<td><code>'ANY'</code></td>\n<td>any records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolveany_hostname\"><code>dnsPromises.resolveAny()</code></a></td>\n</tr>\n<tr>\n<td><code>'CNAME'</code></td>\n<td>canonical name records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvecname_hostname\"><code>dnsPromises.resolveCname()</code></a></td>\n</tr>\n<tr>\n<td><code>'MX'</code></td>\n<td>mail exchange records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvemx_hostname\"><code>dnsPromises.resolveMx()</code></a></td>\n</tr>\n<tr>\n<td><code>'NAPTR'</code></td>\n<td>name authority pointer records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvenaptr_hostname\"><code>dnsPromises.resolveNaptr()</code></a></td>\n</tr>\n<tr>\n<td><code>'NS'</code></td>\n<td>name server records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvens_hostname\"><code>dnsPromises.resolveNs()</code></a></td>\n</tr>\n<tr>\n<td><code>'PTR'</code></td>\n<td>pointer records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolveptr_hostname\"><code>dnsPromises.resolvePtr()</code></a></td>\n</tr>\n<tr>\n<td><code>'SOA'</code></td>\n<td>start of authority records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvesoa_hostname\"><code>dnsPromises.resolveSoa()</code></a></td>\n</tr>\n<tr>\n<td><code>'SRV'</code></td>\n<td>service records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvesrv_hostname\"><code>dnsPromises.resolveSrv()</code></a></td>\n</tr>\n<tr>\n<td><code>'TXT'</code></td>\n<td>text records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[]&gt;</a></td>\n<td><a href=\"#dns_dnspromises_resolvetxt_hostname\"><code>dnsPromises.resolveTxt()</code></a></td>\n</tr>\n</tbody>\n</table>\n<p>On error, the <code>Promise</code> is rejected with an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code>\nis one of the <a href=\"#dns_error_codes\">DNS error codes</a>.</p>"
},
{
"textRaw": "`dnsPromises.resolve4(hostname[, options])`",
"type": "method",
"name": "resolve4",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string} Host name to resolve.",
"name": "hostname",
"type": "string",
"desc": "Host name to resolve."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record. When `true`, the `Promise` is resolved with an array of `{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds.",
"name": "ttl",
"type": "boolean",
"desc": "Retrieve the Time-To-Live value (TTL) of each record. When `true`, the `Promise` is resolved with an array of `{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds."
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve IPv4 addresses (<code>A</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv4\naddresses (e.g. <code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>"
},
{
"textRaw": "`dnsPromises.resolve6(hostname[, options])`",
"type": "method",
"name": "resolve6",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string} Host name to resolve.",
"name": "hostname",
"type": "string",
"desc": "Host name to resolve."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record. When `true`, the `Promise` is resolved with an array of `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds.",
"name": "ttl",
"type": "boolean",
"desc": "Retrieve the Time-To-Live value (TTL) of each record. When `true`, the `Promise` is resolved with an array of `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of strings, with the TTL expressed in seconds."
}
]
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv6\naddresses.</p>"
},
{
"textRaw": "`dnsPromises.resolveAny(hostname)`",
"type": "method",
"name": "resolveAny",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).\nOn success, the <code>Promise</code> is resolved with an array containing various types of\nrecords. Each object has a property <code>type</code> that indicates the type of the\ncurrent record. And depending on the <code>type</code>, additional properties will be\npresent on the object:</p>\n<table>\n<thead>\n<tr>\n<th>Type</th>\n<th>Properties</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>'A'</code></td>\n<td><code>address</code>/<code>ttl</code></td>\n</tr>\n<tr>\n<td><code>'AAAA'</code></td>\n<td><code>address</code>/<code>ttl</code></td>\n</tr>\n<tr>\n<td><code>'CNAME'</code></td>\n<td><code>value</code></td>\n</tr>\n<tr>\n<td><code>'MX'</code></td>\n<td>Refer to <a href=\"#dns_dnspromises_resolvemx_hostname\"><code>dnsPromises.resolveMx()</code></a></td>\n</tr>\n<tr>\n<td><code>'NAPTR'</code></td>\n<td>Refer to <a href=\"#dns_dnspromises_resolvenaptr_hostname\"><code>dnsPromises.resolveNaptr()</code></a></td>\n</tr>\n<tr>\n<td><code>'NS'</code></td>\n<td><code>value</code></td>\n</tr>\n<tr>\n<td><code>'PTR'</code></td>\n<td><code>value</code></td>\n</tr>\n<tr>\n<td><code>'SOA'</code></td>\n<td>Refer to <a href=\"#dns_dnspromises_resolvesoa_hostname\"><code>dnsPromises.resolveSoa()</code></a></td>\n</tr>\n<tr>\n<td><code>'SRV'</code></td>\n<td>Refer to <a href=\"#dns_dnspromises_resolvesrv_hostname\"><code>dnsPromises.resolveSrv()</code></a></td>\n</tr>\n<tr>\n<td><code>'TXT'</code></td>\n<td>This type of record contains an array property called <code>entries</code> which refers to <a href=\"#dns_dnspromises_resolvetxt_hostname\"><code>dnsPromises.resolveTxt()</code></a>, e.g. <code>{ entries: ['...'], type: 'TXT' }</code></td>\n</tr>\n</tbody>\n</table>\n<p>Here is an example of the result object:</p>\n<!-- eslint-disable semi -->\n<pre><code class=\"language-js\">[ { 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</code></pre>"
},
{
"textRaw": "`dnsPromises.resolveCname(hostname)`",
"type": "method",
"name": "resolveCname",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. On success,\nthe <code>Promise</code> is resolved with an array of canonical name records available for\nthe <code>hostname</code> (e.g. <code>['bar.example.com']</code>).</p>"
},
{
"textRaw": "`dnsPromises.resolveMx(hostname)`",
"type": "method",
"name": "resolveMx",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects\ncontaining both a <code>priority</code> and <code>exchange</code> property (e.g.\n<code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>"
},
{
"textRaw": "`dnsPromises.resolveNaptr(hostname)`",
"type": "method",
"name": "resolveNaptr",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve regular expression based records (<code>NAPTR</code>\nrecords) for the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array\nof objects with the following properties:</p>\n<ul>\n<li><code>flags</code></li>\n<li><code>service</code></li>\n<li><code>regexp</code></li>\n<li><code>replacement</code></li>\n<li><code>order</code></li>\n<li><code>preference</code></li>\n</ul>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\n flags: 's',\n service: 'SIP+D2U',\n regexp: '',\n replacement: '_sip._udp.example.com',\n order: 30,\n preference: 100\n}\n</code></pre>"
},
{
"textRaw": "`dnsPromises.resolveNs(hostname)`",
"type": "method",
"name": "resolveNs",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of name server\nrecords available for <code>hostname</code> (e.g.\n<code>['ns1.example.com', 'ns2.example.com']</code>).</p>"
},
{
"textRaw": "`dnsPromises.resolvePtr(hostname)`",
"type": "method",
"name": "resolvePtr",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of strings\ncontaining the reply records.</p>"
},
{
"textRaw": "`dnsPromises.resolveSoa(hostname)`",
"type": "method",
"name": "resolveSoa",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for\nthe <code>hostname</code>. On success, the <code>Promise</code> is resolved with an object with the\nfollowing properties:</p>\n<ul>\n<li><code>nsname</code></li>\n<li><code>hostmaster</code></li>\n<li><code>serial</code></li>\n<li><code>refresh</code></li>\n<li><code>retry</code></li>\n<li><code>expire</code></li>\n<li><code>minttl</code></li>\n</ul>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\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</code></pre>"
},
{
"textRaw": "`dnsPromises.resolveSrv(hostname)`",
"type": "method",
"name": "resolveSrv",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects with\nthe following properties:</p>\n<ul>\n<li><code>priority</code></li>\n<li><code>weight</code></li>\n<li><code>port</code></li>\n<li><code>name</code></li>\n</ul>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\n priority: 10,\n weight: 5,\n port: 21223,\n name: 'service.example.com'\n}\n</code></pre>"
},
{
"textRaw": "`dnsPromises.resolveTxt(hostname)`",
"type": "method",
"name": "resolveTxt",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`hostname` {string}",
"name": "hostname",
"type": "string"
}
]
}
],
"desc": "<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the\n<code>hostname</code>. On success, the <code>Promise</code> is resolved with a two-dimensional array\nof the text records available for <code>hostname</code> (e.g.\n<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of\none record. Depending on the use case, these could be either joined together or\ntreated separately.</p>"
},
{
"textRaw": "`dnsPromises.reverse(ip)`",
"type": "method",
"name": "reverse",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`ip` {string}",
"name": "ip",
"type": "string"
}
]
}
],
"desc": "<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an\narray of host names.</p>\n<p>On error, the <code>Promise</code> is rejected with an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object, where <code>err.code</code>\nis one of the <a href=\"#dns_error_codes\">DNS error codes</a>.</p>"
},
{
"textRaw": "`dnsPromises.setServers(servers)`",
"type": "method",
"name": "setServers",
"meta": {
"added": [
"v10.6.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`servers` {string[]} array of [RFC 5952][] formatted addresses",
"name": "servers",
"type": "string[]",
"desc": "array of [RFC 5952][] formatted addresses"
}
]
}
],
"desc": "<p>Sets the IP address and port of servers to be used when performing DNS\nresolution. The <code>servers</code> argument is an array of <a href=\"https://tools.ietf.org/html/rfc5952#section-6\">RFC 5952</a> formatted\naddresses. If the port is the IANA default DNS port (53) it can be omitted.</p>\n<pre><code class=\"language-js\">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</code></pre>\n<p>An error will be thrown if an invalid address is provided.</p>\n<p>The <code>dnsPromises.setServers()</code> method must not be called while a DNS query is in\nprogress.</p>\n<p>This method works much like\n<a href=\"http://man7.org/linux/man-pages/man5/resolv.conf.5.html\">resolve.conf</a>.\nThat is, if attempting to resolve with the first server provided results in a\n<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> 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.</p>"
}
],
"type": "module",
"displayName": "DNS Promises API"
},
{
"textRaw": "Error codes",
"name": "error_codes",
"desc": "<p>Each DNS query can return one of the following error codes:</p>\n<ul>\n<li><code>dns.NODATA</code>: DNS server returned answer with no data.</li>\n<li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li>\n<li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li>\n<li><code>dns.NOTFOUND</code>: Domain name not found.</li>\n<li><code>dns.NOTIMP</code>: DNS server does not implement requested operation.</li>\n<li><code>dns.REFUSED</code>: DNS server refused query.</li>\n<li><code>dns.BADQUERY</code>: Misformatted DNS query.</li>\n<li><code>dns.BADNAME</code>: Misformatted host name.</li>\n<li><code>dns.BADFAMILY</code>: Unsupported address family.</li>\n<li><code>dns.BADRESP</code>: Misformatted DNS reply.</li>\n<li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li>\n<li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li>\n<li><code>dns.EOF</code>: End of file.</li>\n<li><code>dns.FILE</code>: Error reading file.</li>\n<li><code>dns.NOMEM</code>: Out of memory.</li>\n<li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li>\n<li><code>dns.BADSTR</code>: Misformatted string.</li>\n<li><code>dns.BADFLAGS</code>: Illegal flags specified.</li>\n<li><code>dns.NONAME</code>: Given host name is not numeric.</li>\n<li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li>\n<li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li>\n<li><code>dns.LOADIPHLPAPI</code>: Error loading <code>iphlpapi.dll</code>.</li>\n<li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find <code>GetNetworkParams</code> function.</li>\n<li><code>dns.CANCELLED</code>: DNS query cancelled.</li>\n</ul>",
"type": "module",
"displayName": "Error codes"
},
{
"textRaw": "Implementation considerations",
"name": "implementation_considerations",
"desc": "<p>Although <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> and the various <code>dns.resolve*()/dns.reverse()</code>\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.</p>",
"methods": [
{
"textRaw": "`dns.lookup()`",
"type": "method",
"name": "lookup",
"signatures": [
{
"params": []
}
],
"desc": "<p>Under the hood, <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> uses the same operating system facilities\nas most other programs. For instance, <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> will almost always\nresolve a given name the same way as the <code>ping</code> command. On most POSIX-like\noperating systems, the behavior of the <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> function can be\nmodified by changing settings in <a href=\"http://man7.org/linux/man-pages/man5/nsswitch.conf.5.html\"><code>nsswitch.conf(5)</code></a> and/or <a href=\"http://man7.org/linux/man-pages/man5/resolv.conf.5.html\"><code>resolv.conf(5)</code></a>,\nbut changing these files will change the behavior of all other\nprograms running on the same operating system.</p>\n<p>Though the call to <code>dns.lookup()</code> will be asynchronous from JavaScript's\nperspective, it is implemented as a synchronous call to <a href=\"http://man7.org/linux/man-pages/man3/getaddrinfo.3.html\"><code>getaddrinfo(3)</code></a> that runs\non libuv's threadpool. This can have surprising negative performance\nimplications for some applications, see the <a href=\"cli.html#cli_uv_threadpool_size_size\"><code>UV_THREADPOOL_SIZE</code></a>\ndocumentation for more information.</p>\n<p>Various networking APIs will call <code>dns.lookup()</code> internally to resolve\nhost names. If that is an issue, consider resolving the host name to an address\nusing <code>dns.resolve()</code> and using the address instead of a host name. Also, some\nnetworking APIs (such as <a href=\"net.html#net_socket_connect_options_connectlistener\"><code>socket.connect()</code></a> and <a href=\"dgram.html#dgram_dgram_createsocket_options_callback\"><code>dgram.createSocket()</code></a>)\nallow the default resolver, <code>dns.lookup()</code>, to be replaced.</p>"
}
],
"modules": [
{
"textRaw": "`dns.resolve()`, `dns.resolve*()` and `dns.reverse()`",
"name": "`dns.resolve()`,_`dns.resolve*()`_and_`dns.reverse()`",
"desc": "<p>These functions are implemented quite differently than <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a>. They\ndo not use <a href=\"http://man7.org/linux/man-pages/man3/getaddrinfo.3.html\"><code>getaddrinfo(3)</code></a> and they <em>always</em> perform a DNS query on the\nnetwork. This network communication is always done asynchronously, and does not\nuse libuv's threadpool.</p>\n<p>As a result, these functions cannot have the same negative impact on other\nprocessing that happens on libuv's threadpool that <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a> can have.</p>\n<p>They do not use the same set of configuration files than what <a href=\"#dns_dns_lookup_hostname_options_callback\"><code>dns.lookup()</code></a>\nuses. For instance, <em>they do not use the configuration from <code>/etc/hosts</code></em>.</p>",
"type": "module",
"displayName": "`dns.resolve()`, `dns.resolve*()` and `dns.reverse()`"
}
],
"type": "module",
"displayName": "Implementation considerations"
}
],
"type": "module",
"displayName": "DNS"
}
]
}