/usr/share/doc/nodejs/html/api
{ "type": "module", "source": "doc/api/dns.md", "modules": [ { "textRaw": "DNS", "name": "dns", "introduced_in": "v0.10.0", "stability": 2, "stabilityText": "Stable", "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v16.20.2/lib/dns.js\">lib/dns.js</a></p>\n<p>The <code>node: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=\"#dnslookuphostname-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. To perform name resolution the way other applications on the same\nsystem do, use <a href=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a>.</p>\n<pre><code class=\"language-js\">const dns = require('node: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>node: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=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a> (e.g. <code>/etc/hosts</code>). Use these functions to always perform\nDNS queries, bypassing other name-resolution facilities.</p>\n<pre><code class=\"language-js\">const dns = require('node: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=\"#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=\"#dnssetserversservers\"><code>resolver.setServers()</code></a> does not affect\nother resolvers:</p>\n<pre><code class=\"language-js\">const { Resolver } = require('node: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>node:dns</code> module are available:</p>\n<ul>\n<li><a href=\"#dnsgetservers\"><code>resolver.getServers()</code></a></li>\n<li><a href=\"#dnsresolvehostname-rrtype-callback\"><code>resolver.resolve()</code></a></li>\n<li><a href=\"#dnsresolve4hostname-options-callback\"><code>resolver.resolve4()</code></a></li>\n<li><a href=\"#dnsresolve6hostname-options-callback\"><code>resolver.resolve6()</code></a></li>\n<li><a href=\"#dnsresolveanyhostname-callback\"><code>resolver.resolveAny()</code></a></li>\n<li><a href=\"#dnsresolvecaahostname-callback\"><code>resolver.resolveCaa()</code></a></li>\n<li><a href=\"#dnsresolvecnamehostname-callback\"><code>resolver.resolveCname()</code></a></li>\n<li><a href=\"#dnsresolvemxhostname-callback\"><code>resolver.resolveMx()</code></a></li>\n<li><a href=\"#dnsresolvenaptrhostname-callback\"><code>resolver.resolveNaptr()</code></a></li>\n<li><a href=\"#dnsresolvenshostname-callback\"><code>resolver.resolveNs()</code></a></li>\n<li><a href=\"#dnsresolveptrhostname-callback\"><code>resolver.resolvePtr()</code></a></li>\n<li><a href=\"#dnsresolvesoahostname-callback\"><code>resolver.resolveSoa()</code></a></li>\n<li><a href=\"#dnsresolvesrvhostname-callback\"><code>resolver.resolveSrv()</code></a></li>\n<li><a href=\"#dnsresolvetxthostname-callback\"><code>resolver.resolveTxt()</code></a></li>\n<li><a href=\"#dnsreverseip-callback\"><code>resolver.reverse()</code></a></li>\n<li><a href=\"#dnssetserversservers\"><code>resolver.setServers()</code></a></li>\n</ul>", "methods": [ { "textRaw": "`Resolver([options])`", "type": "method", "name": "Resolver", "meta": { "added": [ "v8.3.0" ], "changes": [ { "version": "v16.7.0", "pr-url": "https://github.com/nodejs/node/pull/39610", "description": "The `options` object now accepts a `tries` option." }, { "version": "v12.18.3", "pr-url": "https://github.com/nodejs/node/pull/33472", "description": "The constructor now accepts an `options` object. The single supported option is `timeout`." } ] }, "signatures": [ { "params": [] } ], "desc": "<p>Create a new resolver.</p>\n<ul>\n<li><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a>\n<ul>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><integer></a> Query timeout in milliseconds, or <code>-1</code> to use the\ndefault timeout.</li>\n<li><code>tries</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><integer></a> The number of tries the resolver will try contacting\neach name server before giving up. <strong>Default:</strong> <code>4</code></li>\n</ul>\n</li>\n</ul>" }, { "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>" }, { "textRaw": "`resolver.setLocalAddress([ipv4][, ipv6])`", "type": "method", "name": "setLocalAddress", "meta": { "added": [ "v15.1.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`ipv4` {string} A string representation of an IPv4 address. **Default:** `'0.0.0.0'`", "name": "ipv4", "type": "string", "default": "`'0.0.0.0'`", "desc": "A string representation of an IPv4 address." }, { "textRaw": "`ipv6` {string} A string representation of an IPv6 address. **Default:** `'::0'`", "name": "ipv6", "type": "string", "default": "`'::0'`", "desc": "A string representation of an IPv6 address." } ] } ], "desc": "<p>The resolver instance will send its requests from the specified IP address.\nThis allows programs to specify outbound interfaces when used on multi-homed\nsystems.</p>\n<p>If a v4 or v6 address is not specified, it is set to the default and the\noperating system will choose a local address automatically.</p>\n<p>The resolver will use the v4 local address when making requests to IPv4 DNS\nservers, and the v6 local address when making requests to IPv6 DNS servers.\nThe <code>rrtype</code> of resolution requests has no impact on the local address used.</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. Default value is configurable using [`dns.setDefaultResultOrder()`][] or [`--dns-result-order`][]. 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. Default value is configurable using [`dns.setDefaultResultOrder()`][] or [`--dns-result-order`][]. 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#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=\"#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('node: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#utilpromisifyoriginal\"><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": [ "v13.13.0", "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=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a>.</p>\n<ul>\n<li><code>dns.ADDRCONFIG</code>: Limits returned address types to the types of non-loopback\naddresses configured on the system. For example, IPv4 addresses are only\nreturned if the current system has at least one IPv4 address configured.</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#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('node: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#utilpromisifyoriginal\"><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\"><string></a></td>\n<td><a href=\"#dnsresolve4hostname-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\"><string></a></td>\n<td><a href=\"#dnsresolve6hostname-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\"><Object></a></td>\n<td><a href=\"#dnsresolveanyhostname-callback\"><code>dns.resolveAny()</code></a></td>\n</tr>\n<tr>\n<td><code>'CAA'</code></td>\n<td>CA authorization records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a></td>\n<td><a href=\"#dnsresolvecaahostname-callback\"><code>dns.resolveCaa()</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\"><string></a></td>\n<td><a href=\"#dnsresolvecnamehostname-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\"><Object></a></td>\n<td><a href=\"#dnsresolvemxhostname-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\"><Object></a></td>\n<td><a href=\"#dnsresolvenaptrhostname-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\"><string></a></td>\n<td><a href=\"#dnsresolvenshostname-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\"><string></a></td>\n<td><a href=\"#dnsresolveptrhostname-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\"><Object></a></td>\n<td><a href=\"#dnsresolvesoahostname-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\"><Object></a></td>\n<td><a href=\"#dnsresolvesrvhostname-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\"><string[]></a></td>\n<td><a href=\"#dnsresolvetxthostname-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#class-error\"><code>Error</code></a> object, where <code>err.code</code> is one of the\n<a href=\"#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} Retrieves 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": "Retrieves 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 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=\"#dnsresolvemxhostname-callback\"><code>dns.resolveMx()</code></a></td>\n</tr>\n<tr>\n<td><code>'NAPTR'</code></td>\n<td>Refer to <a href=\"#dnsresolvenaptrhostname-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=\"#dnsresolvesoahostname-callback\"><code>dns.resolveSoa()</code></a></td>\n</tr>\n<tr>\n<td><code>'SRV'</code></td>\n<td>Refer to <a href=\"#dnsresolvesrvhostname-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=\"#dnsresolvetxthostname-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=\"#dnsresolve4hostname-options-callback\"><code>dns.resolve4()</code></a>,\n<a href=\"#dnsresolvemxhostname-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.resolveCaa(hostname, callback)`", "type": "method", "name": "resolveCaa", "meta": { "added": [ "v15.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": "`records` {Object\\[]}", "name": "records", "type": "Object\\[]" } ] } ] } ], "desc": "<p>Uses the DNS protocol to resolve <code>CAA</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 certification authority authorization records\navailable for the <code>hostname</code> (e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.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": [] } ], "desc": "<!--lint disable no-undefined-references list-item-bullet-indent-->\n<ul>\n<li><code>hostname</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a></li>\n<li><code>callback</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\"><Function></a>\n<ul>\n<li><code>err</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error\" class=\"type\"><Error></a></li>\n<li><code>records</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string[][]></a></li>\n</ul>\n</li>\n</ul>\n<!--lint enable no-undefined-references list-item-bullet-indent-->\n<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#class-error\"><code>Error</code></a> object, where <code>err.code</code> is\none of the <a href=\"#error-codes\">DNS error codes</a>.</p>" }, { "textRaw": "`dns.setDefaultResultOrder(order)`", "type": "method", "name": "setDefaultResultOrder", "meta": { "added": [ "v16.4.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`order` {string} must be `'ipv4first'` or `'verbatim'`.", "name": "order", "type": "string", "desc": "must be `'ipv4first'` or `'verbatim'`." } ] } ], "desc": "<p>Set the default value of <code>verbatim</code> in <a href=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a> and\n<a href=\"#dnspromiseslookuphostname-options\"><code>dnsPromises.lookup()</code></a>. The value could be:</p>\n<ul>\n<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>\n<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>\n</ul>\n<p>The default is <code>ipv4first</code> and <a href=\"#dnssetdefaultresultorderorder\"><code>dns.setDefaultResultOrder()</code></a> have higher\npriority than <a href=\"cli.html#--dns-result-orderorder\"><code>--dns-result-order</code></a>. When using <a href=\"worker_threads.html\">worker threads</a>,\n<a href=\"#dnssetdefaultresultorderorder\"><code>dns.setDefaultResultOrder()</code></a> from the main thread won't affect the default\ndns orders in workers.</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=\"#dnssetserversservers\"><code>dns.setServers()</code></a> method affects only <a href=\"#dnsresolvehostname-rrtype-callback\"><code>dns.resolve()</code></a>,\n<code>dns.resolve*()</code> and <a href=\"#dnsreverseip-callback\"><code>dns.reverse()</code></a> (and specifically <em>not</em>\n<a href=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a>).</p>\n<p>This method works much like\n<a href=\"https://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", "meta": { "added": [ "v10.6.0" ], "changes": [ { "version": "v15.0.0", "pr-url": "https://github.com/nodejs/node/pull/32953", "description": "Exposed as `require('dns/promises')`." }, { "version": [ "v11.14.0", "v10.17.0" ], "pr-url": "https://github.com/nodejs/node/pull/26592", "description": "This API is no longer experimental." } ] }, "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('node:dns').promises</code> or <code>require('node: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=\"#dnspromisessetserversservers\"><code>resolver.setServers()</code></a> does not affect\nother resolvers:</p>\n<pre><code class=\"language-js\">const { Resolver } = require('node: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=\"#dnspromisesgetservers\"><code>resolver.getServers()</code></a></li>\n<li><a href=\"#dnspromisesresolvehostname-rrtype\"><code>resolver.resolve()</code></a></li>\n<li><a href=\"#dnspromisesresolve4hostname-options\"><code>resolver.resolve4()</code></a></li>\n<li><a href=\"#dnspromisesresolve6hostname-options\"><code>resolver.resolve6()</code></a></li>\n<li><a href=\"#dnspromisesresolveanyhostname\"><code>resolver.resolveAny()</code></a></li>\n<li><a href=\"#dnspromisesresolvecaahostname\"><code>resolver.resolveCaa()</code></a></li>\n<li><a href=\"#dnspromisesresolvecnamehostname\"><code>resolver.resolveCname()</code></a></li>\n<li><a href=\"#dnspromisesresolvemxhostname\"><code>resolver.resolveMx()</code></a></li>\n<li><a href=\"#dnspromisesresolvenaptrhostname\"><code>resolver.resolveNaptr()</code></a></li>\n<li><a href=\"#dnspromisesresolvenshostname\"><code>resolver.resolveNs()</code></a></li>\n<li><a href=\"#dnspromisesresolveptrhostname\"><code>resolver.resolvePtr()</code></a></li>\n<li><a href=\"#dnspromisesresolvesoahostname\"><code>resolver.resolveSoa()</code></a></li>\n<li><a href=\"#dnspromisesresolvesrvhostname\"><code>resolver.resolveSrv()</code></a></li>\n<li><a href=\"#dnspromisesresolvetxthostname\"><code>resolver.resolveTxt()</code></a></li>\n<li><a href=\"#dnspromisesreverseip\"><code>resolver.reverse()</code></a></li>\n<li><a href=\"#dnspromisessetserversservers\"><code>resolver.setServers()</code></a></li>\n</ul>" } ], "methods": [ { "textRaw": "`resolver.cancel()`", "type": "method", "name": "cancel", "meta": { "added": [ "v15.3.0" ], "changes": [] }, "signatures": [ { "params": [] } ], "desc": "<p>Cancel all outstanding DNS queries made by this resolver. The corresponding\npromises will be rejected with an error with the code <code>ECANCELLED</code>.</p>" }, { "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. Default value is configurable using [`dns.setDefaultResultOrder()`][] or [`--dns-result-order`][]. 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. Default value is configurable using [`dns.setDefaultResultOrder()`][] or [`--dns-result-order`][]. 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#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=\"#dnspromiseslookuphostname-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=\"#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('node: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#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('node: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\"><string></a></td>\n<td><a href=\"#dnspromisesresolve4hostname-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\"><string></a></td>\n<td><a href=\"#dnspromisesresolve6hostname-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\"><Object></a></td>\n<td><a href=\"#dnspromisesresolveanyhostname\"><code>dnsPromises.resolveAny()</code></a></td>\n</tr>\n<tr>\n<td><code>'CAA'</code></td>\n<td>CA authorization records</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a></td>\n<td><a href=\"#dnspromisesresolvecaahostname\"><code>dnsPromises.resolveCaa()</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\"><string></a></td>\n<td><a href=\"#dnspromisesresolvecnamehostname\"><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\"><Object></a></td>\n<td><a href=\"#dnspromisesresolvemxhostname\"><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\"><Object></a></td>\n<td><a href=\"#dnspromisesresolvenaptrhostname\"><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\"><string></a></td>\n<td><a href=\"#dnspromisesresolvenshostname\"><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\"><string></a></td>\n<td><a href=\"#dnspromisesresolveptrhostname\"><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\"><Object></a></td>\n<td><a href=\"#dnspromisesresolvesoahostname\"><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\"><Object></a></td>\n<td><a href=\"#dnspromisesresolvesrvhostname\"><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\"><string[]></a></td>\n<td><a href=\"#dnspromisesresolvetxthostname\"><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#class-error\"><code>Error</code></a> object, where <code>err.code</code>\nis one of the <a href=\"#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=\"#dnspromisesresolvemxhostname\"><code>dnsPromises.resolveMx()</code></a></td>\n</tr>\n<tr>\n<td><code>'NAPTR'</code></td>\n<td>Refer to <a href=\"#dnspromisesresolvenaptrhostname\"><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=\"#dnspromisesresolvesoahostname\"><code>dnsPromises.resolveSoa()</code></a></td>\n</tr>\n<tr>\n<td><code>'SRV'</code></td>\n<td>Refer to <a href=\"#dnspromisesresolvesrvhostname\"><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=\"#dnspromisesresolvetxthostname\"><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.resolveCaa(hostname)`", "type": "method", "name": "resolveCaa", "meta": { "added": [ "v15.0.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`hostname` {string}", "name": "hostname", "type": "string" } ] } ], "desc": "<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. On success,\nthe <code>Promise</code> is resolved with an array of objects containing available\ncertification authority authorization records available for the <code>hostname</code>\n(e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]</code>).</p>" }, { "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#class-error\"><code>Error</code></a> object, where <code>err.code</code>\nis one of the <a href=\"#error-codes\">DNS error codes</a>.</p>" }, { "textRaw": "`dnsPromises.setDefaultResultOrder(order)`", "type": "method", "name": "setDefaultResultOrder", "meta": { "added": [ "v16.4.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`order` {string} must be `'ipv4first'` or `'verbatim'`.", "name": "order", "type": "string", "desc": "must be `'ipv4first'` or `'verbatim'`." } ] } ], "desc": "<p>Set the default value of <code>verbatim</code> in <a href=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a> and\n<a href=\"#dnspromiseslookuphostname-options\"><code>dnsPromises.lookup()</code></a>. The value could be:</p>\n<ul>\n<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>\n<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>\n</ul>\n<p>The default is <code>ipv4first</code> and <a href=\"#dnspromisessetdefaultresultorderorder\"><code>dnsPromises.setDefaultResultOrder()</code></a> have\nhigher priority than <a href=\"cli.html#--dns-result-orderorder\"><code>--dns-result-order</code></a>. When using <a href=\"worker_threads.html\">worker threads</a>,\n<a href=\"#dnspromisessetdefaultresultorderorder\"><code>dnsPromises.setDefaultResultOrder()</code></a> from the main thread won't affect the\ndefault dns orders in workers.</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=\"https://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 an 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 the 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>\n<p>The <code>dnsPromises</code> API also exports the above error codes, e.g., <code>dnsPromises.NODATA</code>.</p>", "type": "module", "displayName": "Error codes" }, { "textRaw": "Implementation considerations", "name": "implementation_considerations", "desc": "<p>Although <a href=\"#dnslookuphostname-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=\"#dnslookuphostname-options-callback\"><code>dns.lookup()</code></a> uses the same operating system facilities\nas most other programs. For instance, <a href=\"#dnslookuphostname-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=\"#dnslookuphostname-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#uv_threadpool_sizesize\"><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#socketconnectoptions-connectlistener\"><code>socket.connect()</code></a> and <a href=\"dgram.html#dgramcreatesocketoptions-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=\"#dnslookuphostname-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=\"#dnslookuphostname-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=\"#dnslookuphostname-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" } ] }
.
Edit
..
Edit
addons.html
Edit
addons.json
Edit
addons.md
Edit
all.html
Edit
all.json
Edit
assert.html
Edit
assert.json
Edit
assert.md
Edit
assets
Edit
async_context.html
Edit
async_context.json
Edit
async_context.md
Edit
async_hooks.html
Edit
async_hooks.json
Edit
async_hooks.md
Edit
buffer.html
Edit
buffer.json
Edit
buffer.md
Edit
child_process.html
Edit
child_process.json
Edit
child_process.md
Edit
cli.html
Edit
cli.json
Edit
cli.md
Edit
cluster.html
Edit
cluster.json
Edit
cluster.md
Edit
console.html
Edit
console.json
Edit
console.md
Edit
corepack.html
Edit
corepack.json
Edit
corepack.md
Edit
crypto.html
Edit
crypto.json
Edit
crypto.md
Edit
debugger.html
Edit
debugger.json
Edit
debugger.md
Edit
deprecations.html
Edit
deprecations.json
Edit
deprecations.md
Edit
dgram.html
Edit
dgram.json
Edit
dgram.md
Edit
diagnostics_channel.html
Edit
diagnostics_channel.json
Edit
diagnostics_channel.md
Edit
dns.html
Edit
dns.json
Edit
dns.md
Edit
documentation.html
Edit
documentation.json
Edit
documentation.md
Edit
domain.html
Edit
domain.json
Edit
domain.md
Edit
embedding.html
Edit
embedding.json
Edit
embedding.md
Edit
errors.html
Edit
errors.json
Edit
errors.md
Edit
esm.html
Edit
esm.json
Edit
esm.md
Edit
events.html
Edit
events.json
Edit
events.md
Edit
fs.html
Edit
fs.json
Edit
fs.md
Edit
globals.html
Edit
globals.json
Edit
globals.md
Edit
http.html
Edit
http.json
Edit
http.md
Edit
http2.html
Edit
http2.json
Edit
http2.md
Edit
https.html
Edit
https.json
Edit
https.md
Edit
index.html
Edit
index.json
Edit
index.md
Edit
inspector.html
Edit
inspector.json
Edit
inspector.md
Edit
intl.html
Edit
intl.json
Edit
intl.md
Edit
module.html
Edit
module.json
Edit
module.md
Edit
modules.html
Edit
modules.json
Edit
modules.md
Edit
n-api.html
Edit
n-api.json
Edit
n-api.md
Edit
net.html
Edit
net.json
Edit
net.md
Edit
os.html
Edit
os.json
Edit
os.md
Edit
packages.html
Edit
packages.json
Edit
packages.md
Edit
path.html
Edit
path.json
Edit
path.md
Edit
perf_hooks.html
Edit
perf_hooks.json
Edit
perf_hooks.md
Edit
permissions.html
Edit
permissions.json
Edit
permissions.md
Edit
policy.html
Edit
policy.json
Edit
policy.md
Edit
process.html
Edit
process.json
Edit
process.md
Edit
punycode.html
Edit
punycode.json
Edit
punycode.md
Edit
querystring.html
Edit
querystring.json
Edit
querystring.md
Edit
readline.html
Edit
readline.json
Edit
readline.md
Edit
repl.html
Edit
repl.json
Edit
repl.md
Edit
report.html
Edit
report.json
Edit
report.md
Edit
stream.html
Edit
stream.json
Edit
stream.md
Edit
string_decoder.html
Edit
string_decoder.json
Edit
string_decoder.md
Edit
synopsis.html
Edit
synopsis.json
Edit
synopsis.md
Edit
test.html
Edit
test.json
Edit
test.md
Edit
timers.html
Edit
timers.json
Edit
timers.md
Edit
tls.html
Edit
tls.json
Edit
tls.md
Edit
tracing.html
Edit
tracing.json
Edit
tracing.md
Edit
tty.html
Edit
tty.json
Edit
tty.md
Edit
url.html
Edit
url.json
Edit
url.md
Edit
util.html
Edit
util.json
Edit
util.md
Edit
v8.html
Edit
v8.json
Edit
v8.md
Edit
vm.html
Edit
vm.json
Edit
vm.md
Edit
wasi.html
Edit
wasi.json
Edit
wasi.md
Edit
webcrypto.html
Edit
webcrypto.json
Edit
webcrypto.md
Edit
webstreams.html
Edit
webstreams.json
Edit
webstreams.md
Edit
worker_threads.html
Edit
worker_threads.json
Edit
worker_threads.md
Edit
zlib.html
Edit
zlib.json
Edit
zlib.md
Edit