• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en">
3<head>
4  <meta charset="utf-8">
5  <meta name="viewport" content="width=device-width">
6  <meta name="nodejs.org:node-version" content="v14.19.1">
7  <title>DNS | Node.js v14.19.1 Documentation</title>
8  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
9  <link rel="stylesheet" href="assets/style.css">
10  <link rel="stylesheet" href="assets/hljs.css">
11  <link rel="canonical" href="https://nodejs.org/api/dns.html">
12</head>
13<body class="alt apidoc" id="api-section-dns">
14  <div id="content" class="clearfix">
15    <div id="column2" class="interior">
16      <div id="intro" class="interior">
17        <a href="/" title="Go back to the home page">
18          Node.js
19        </a>
20      </div>
21      <ul>
22<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
23<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
24</ul>
25<hr class="line">
26<ul>
27<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
28<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
29<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
30<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
31<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
32<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
33<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
34<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
35<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
36<li><a href="console.html" class="nav-console">Console</a></li>
37<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
38<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
39<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
40<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
41<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
42<li><a href="dns.html" class="nav-dns active">DNS</a></li>
43<li><a href="domain.html" class="nav-domain">Domain</a></li>
44<li><a href="errors.html" class="nav-errors">Errors</a></li>
45<li><a href="events.html" class="nav-events">Events</a></li>
46<li><a href="fs.html" class="nav-fs">File system</a></li>
47<li><a href="globals.html" class="nav-globals">Globals</a></li>
48<li><a href="http.html" class="nav-http">HTTP</a></li>
49<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
50<li><a href="https.html" class="nav-https">HTTPS</a></li>
51<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
52<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
53<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
54<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
55<li><a href="module.html" class="nav-module">Modules: <code>module</code> API</a></li>
56<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
57<li><a href="net.html" class="nav-net">Net</a></li>
58<li><a href="os.html" class="nav-os">OS</a></li>
59<li><a href="path.html" class="nav-path">Path</a></li>
60<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
61<li><a href="policy.html" class="nav-policy">Policies</a></li>
62<li><a href="process.html" class="nav-process">Process</a></li>
63<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
64<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
65<li><a href="readline.html" class="nav-readline">Readline</a></li>
66<li><a href="repl.html" class="nav-repl">REPL</a></li>
67<li><a href="report.html" class="nav-report">Report</a></li>
68<li><a href="stream.html" class="nav-stream">Stream</a></li>
69<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
70<li><a href="timers.html" class="nav-timers">Timers</a></li>
71<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
72<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
73<li><a href="tty.html" class="nav-tty">TTY</a></li>
74<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
75<li><a href="url.html" class="nav-url">URL</a></li>
76<li><a href="util.html" class="nav-util">Utilities</a></li>
77<li><a href="v8.html" class="nav-v8">V8</a></li>
78<li><a href="vm.html" class="nav-vm">VM</a></li>
79<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
80<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
81<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
82</ul>
83<hr class="line">
84<ul>
85<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
86</ul>
87    </div>
88
89    <div id="column1" data-id="dns" class="interior">
90      <header>
91        <div class="header-container">
92          <h1>Node.js v14.19.1 documentation</h1>
93          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
94            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
95              <path fill="none" d="M0 0h24v24H0z" />
96              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
97              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
98            </svg>
99            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
100              <path d="M0 0h24v24H0z" fill="none" />
101              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
102            </svg>
103          </button>
104        </div>
105        <div id="gtoc">
106          <ul>
107            <li>
108              <a href="index.html">Index</a>
109            </li>
110            <li>
111              <a href="all.html">View on single page</a>
112            </li>
113            <li>
114              <a href="dns.json">View as JSON</a>
115            </li>
116
117    <li class="version-picker">
118      <a href="#">View another version <span>&#x25bc;</span></a>
119      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v17.x/api/dns.html">17.x</a></li>
120<li><a href="https://nodejs.org/docs/latest-v16.x/api/dns.html">16.x <b>LTS</b></a></li>
121<li><a href="https://nodejs.org/docs/latest-v15.x/api/dns.html">15.x</a></li>
122<li><a href="https://nodejs.org/docs/latest-v14.x/api/dns.html">14.x <b>LTS</b></a></li>
123<li><a href="https://nodejs.org/docs/latest-v13.x/api/dns.html">13.x</a></li>
124<li><a href="https://nodejs.org/docs/latest-v12.x/api/dns.html">12.x <b>LTS</b></a></li>
125<li><a href="https://nodejs.org/docs/latest-v11.x/api/dns.html">11.x</a></li>
126<li><a href="https://nodejs.org/docs/latest-v10.x/api/dns.html">10.x</a></li>
127<li><a href="https://nodejs.org/docs/latest-v9.x/api/dns.html">9.x</a></li>
128<li><a href="https://nodejs.org/docs/latest-v8.x/api/dns.html">8.x</a></li>
129<li><a href="https://nodejs.org/docs/latest-v7.x/api/dns.html">7.x</a></li>
130<li><a href="https://nodejs.org/docs/latest-v6.x/api/dns.html">6.x</a></li>
131<li><a href="https://nodejs.org/docs/latest-v5.x/api/dns.html">5.x</a></li>
132<li><a href="https://nodejs.org/docs/latest-v4.x/api/dns.html">4.x</a></li>
133<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/dns.html">0.12.x</a></li>
134<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/dns.html">0.10.x</a></li></ol>
135    </li>
136
137            <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/dns.md">Edit on GitHub</a></li>
138          </ul>
139        </div>
140        <hr>
141      </header>
142
143      <details id="toc" open><summary>Table of contents</summary><ul>
144<li><span class="stability_2"><a href="#dns_dns">DNS</a></span>
145<ul>
146<li><a href="#dns_class_dns_resolver">Class: <code>dns.Resolver</code></a>
147<ul>
148<li><a href="#dns_resolver_options"><code>Resolver([options])</code></a></li>
149<li><a href="#dns_resolver_cancel"><code>resolver.cancel()</code></a></li>
150<li><a href="#dns_resolver_setlocaladdress_ipv4_ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</code></a></li>
151</ul>
152</li>
153<li><a href="#dns_dns_getservers"><code>dns.getServers()</code></a></li>
154<li><a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup(hostname[, options], callback)</code></a>
155<ul>
156<li><a href="#dns_supported_getaddrinfo_flags">Supported getaddrinfo flags</a></li>
157</ul>
158</li>
159<li><a href="#dns_dns_lookupservice_address_port_callback"><code>dns.lookupService(address, port, callback)</code></a></li>
160<li><a href="#dns_dns_resolve_hostname_rrtype_callback"><code>dns.resolve(hostname[, rrtype], callback)</code></a></li>
161<li><a href="#dns_dns_resolve4_hostname_options_callback"><code>dns.resolve4(hostname[, options], callback)</code></a></li>
162<li><a href="#dns_dns_resolve6_hostname_options_callback"><code>dns.resolve6(hostname[, options], callback)</code></a></li>
163<li><a href="#dns_dns_resolveany_hostname_callback"><code>dns.resolveAny(hostname, callback)</code></a></li>
164<li><a href="#dns_dns_resolvecname_hostname_callback"><code>dns.resolveCname(hostname, callback)</code></a></li>
165<li><a href="#dns_dns_resolvecaa_hostname_callback"><code>dns.resolveCaa(hostname, callback)</code></a></li>
166<li><a href="#dns_dns_resolvemx_hostname_callback"><code>dns.resolveMx(hostname, callback)</code></a></li>
167<li><a href="#dns_dns_resolvenaptr_hostname_callback"><code>dns.resolveNaptr(hostname, callback)</code></a></li>
168<li><a href="#dns_dns_resolvens_hostname_callback"><code>dns.resolveNs(hostname, callback)</code></a></li>
169<li><a href="#dns_dns_resolveptr_hostname_callback"><code>dns.resolvePtr(hostname, callback)</code></a></li>
170<li><a href="#dns_dns_resolvesoa_hostname_callback"><code>dns.resolveSoa(hostname, callback)</code></a></li>
171<li><a href="#dns_dns_resolvesrv_hostname_callback"><code>dns.resolveSrv(hostname, callback)</code></a></li>
172<li><a href="#dns_dns_resolvetxt_hostname_callback"><code>dns.resolveTxt(hostname, callback)</code></a></li>
173<li><a href="#dns_dns_reverse_ip_callback"><code>dns.reverse(ip, callback)</code></a></li>
174<li><a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder(order)</code></a></li>
175<li><a href="#dns_dns_setservers_servers"><code>dns.setServers(servers)</code></a></li>
176<li><a href="#dns_dns_promises_api">DNS promises API</a>
177<ul>
178<li><a href="#dns_class_dnspromises_resolver">Class: <code>dnsPromises.Resolver</code></a></li>
179<li><a href="#dns_resolver_cancel_1"><code>resolver.cancel()</code></a></li>
180<li><a href="#dns_dnspromises_getservers"><code>dnsPromises.getServers()</code></a></li>
181<li><a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup(hostname[, options])</code></a></li>
182<li><a href="#dns_dnspromises_lookupservice_address_port"><code>dnsPromises.lookupService(address, port)</code></a></li>
183<li><a href="#dns_dnspromises_resolve_hostname_rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</code></a></li>
184<li><a href="#dns_dnspromises_resolve4_hostname_options"><code>dnsPromises.resolve4(hostname[, options])</code></a></li>
185<li><a href="#dns_dnspromises_resolve6_hostname_options"><code>dnsPromises.resolve6(hostname[, options])</code></a></li>
186<li><a href="#dns_dnspromises_resolveany_hostname"><code>dnsPromises.resolveAny(hostname)</code></a></li>
187<li><a href="#dns_dnspromises_resolvecaa_hostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li>
188<li><a href="#dns_dnspromises_resolvecname_hostname"><code>dnsPromises.resolveCname(hostname)</code></a></li>
189<li><a href="#dns_dnspromises_resolvemx_hostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
190<li><a href="#dns_dnspromises_resolvenaptr_hostname"><code>dnsPromises.resolveNaptr(hostname)</code></a></li>
191<li><a href="#dns_dnspromises_resolvens_hostname"><code>dnsPromises.resolveNs(hostname)</code></a></li>
192<li><a href="#dns_dnspromises_resolveptr_hostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li>
193<li><a href="#dns_dnspromises_resolvesoa_hostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li>
194<li><a href="#dns_dnspromises_resolvesrv_hostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li>
195<li><a href="#dns_dnspromises_resolvetxt_hostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li>
196<li><a href="#dns_dnspromises_reverse_ip"><code>dnsPromises.reverse(ip)</code></a></li>
197<li><a href="#dns_dnspromises_setdefaultresultorder_order"><code>dnsPromises.setDefaultResultOrder(order)</code></a></li>
198<li><a href="#dns_dnspromises_setservers_servers"><code>dnsPromises.setServers(servers)</code></a></li>
199</ul>
200</li>
201<li><a href="#dns_error_codes">Error codes</a></li>
202<li><a href="#dns_implementation_considerations">Implementation considerations</a>
203<ul>
204<li><a href="#dns_dns_lookup"><code>dns.lookup()</code></a></li>
205<li><a href="#dns_dns_resolve_dns_resolve_and_dns_reverse"><code>dns.resolve()</code>, <code>dns.resolve*()</code> and <code>dns.reverse()</code></a></li>
206</ul>
207</li>
208</ul>
209</li>
210</ul></details>
211
212      <div id="apicontent">
213        <h2>DNS<span><a class="mark" href="#dns_dns" id="dns_dns">#</a></span></h2>
214
215<p></p><div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p>
216<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v14.19.1/lib/dns.js">lib/dns.js</a></p>
217<p>The <code>dns</code> module enables name resolution. For example, use it to look up IP
218addresses of host names.</p>
219<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
220DNS protocol for lookups. <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> uses the operating system
221facilities to perform name resolution. It may not need to perform any network
222communication. To perform name resolution the way other applications on the same
223system do, use <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>.</p>
224<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>);
225
226dns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.org'</span>, <span class="hljs-function">(<span class="hljs-params">err, address, family</span>) =></span> {
227  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'address: %j family: IPv%s'</span>, address, family);
228});
229<span class="hljs-comment">// address: "93.184.216.34" family: IPv4</span></code></pre>
230<p>All other functions in the <code>dns</code> module connect to an actual DNS server to
231perform name resolution. They will always use the network to perform DNS
232queries. These functions do not use the same set of configuration files used by
233<a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> (e.g. <code>/etc/hosts</code>). Use these functions to always perform
234DNS queries, bypassing other name-resolution facilities.</p>
235<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>);
236
237dns.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'archive.org'</span>, <span class="hljs-function">(<span class="hljs-params">err, addresses</span>) =></span> {
238  <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">throw</span> err;
239
240  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`addresses: <span class="hljs-subst">${<span class="hljs-built_in">JSON</span>.stringify(addresses)}</span>`</span>);
241
242  addresses.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">a</span>) =></span> {
243    dns.<span class="hljs-title function_">reverse</span>(a, <span class="hljs-function">(<span class="hljs-params">err, hostnames</span>) =></span> {
244      <span class="hljs-keyword">if</span> (err) {
245        <span class="hljs-keyword">throw</span> err;
246      }
247      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`reverse for <span class="hljs-subst">${a}</span>: <span class="hljs-subst">${<span class="hljs-built_in">JSON</span>.stringify(hostnames)}</span>`</span>);
248    });
249  });
250});</code></pre>
251<p>See the <a href="#dns_implementation_considerations">Implementation considerations section</a> for more information.</p>
252<section><h3>Class: <code>dns.Resolver</code><span><a class="mark" href="#dns_class_dns_resolver" id="dns_class_dns_resolver">#</a></span></h3>
253<div class="api_metadata">
254<span>Added in: v8.3.0</span>
255</div>
256<p>An independent resolver for DNS requests.</p>
257<p>Creating a new resolver uses the default server settings. Setting
258the servers used for a resolver using
259<a href="#dns_dns_setservers_servers"><code>resolver.setServers()</code></a> does not affect
260other resolvers:</p>
261<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">Resolver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>);
262<span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Resolver</span>();
263resolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'</span>]);
264
265<span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global settings.</span>
266resolver.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>, <span class="hljs-function">(<span class="hljs-params">err, addresses</span>) =></span> {
267  <span class="hljs-comment">// ...</span>
268});</code></pre>
269<p>The following methods from the <code>dns</code> module are available:</p>
270<ul>
271<li><a href="#dns_dns_getservers"><code>resolver.getServers()</code></a></li>
272<li><a href="#dns_dns_resolve_hostname_rrtype_callback"><code>resolver.resolve()</code></a></li>
273<li><a href="#dns_dns_resolve4_hostname_options_callback"><code>resolver.resolve4()</code></a></li>
274<li><a href="#dns_dns_resolve6_hostname_options_callback"><code>resolver.resolve6()</code></a></li>
275<li><a href="#dns_dns_resolveany_hostname_callback"><code>resolver.resolveAny()</code></a></li>
276<li><a href="#dns_dns_resolvecaa_hostname_callback"><code>resolver.resolveCaa()</code></a></li>
277<li><a href="#dns_dns_resolvecname_hostname_callback"><code>resolver.resolveCname()</code></a></li>
278<li><a href="#dns_dns_resolvemx_hostname_callback"><code>resolver.resolveMx()</code></a></li>
279<li><a href="#dns_dns_resolvenaptr_hostname_callback"><code>resolver.resolveNaptr()</code></a></li>
280<li><a href="#dns_dns_resolvens_hostname_callback"><code>resolver.resolveNs()</code></a></li>
281<li><a href="#dns_dns_resolveptr_hostname_callback"><code>resolver.resolvePtr()</code></a></li>
282<li><a href="#dns_dns_resolvesoa_hostname_callback"><code>resolver.resolveSoa()</code></a></li>
283<li><a href="#dns_dns_resolvesrv_hostname_callback"><code>resolver.resolveSrv()</code></a></li>
284<li><a href="#dns_dns_resolvetxt_hostname_callback"><code>resolver.resolveTxt()</code></a></li>
285<li><a href="#dns_dns_reverse_ip_callback"><code>resolver.reverse()</code></a></li>
286<li><a href="#dns_dns_setservers_servers"><code>resolver.setServers()</code></a></li>
287</ul>
288<h4><code>Resolver([options])</code><span><a class="mark" href="#dns_resolver_options" id="dns_resolver_options">#</a></span></h4>
289<div class="api_metadata">
290<details class="changelog"><summary>History</summary>
291<table>
292<tbody><tr><th>Version</th><th>Changes</th></tr>
293<tr><td>v14.18.0</td>
294<td><p>The <code>options</code> object now accepts a <code>tries</code> option.</p></td></tr>
295<tr><td>v14.5.0</td>
296<td><p>The constructor now accepts an <code>options</code> object. The single supported option is <code>timeout</code>.</p></td></tr>
297<tr><td>v8.3.0</td>
298<td><p><span>Added in: v8.3.0</span></p></td></tr>
299</tbody></table>
300</details>
301</div>
302<p>Create a new resolver.</p>
303<ul>
304<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
305<ul>
306<li><code>timeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Query timeout in milliseconds, or <code>-1</code> to use the
307default timeout.</li>
308<li><code>tries</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The number of tries the resolver will try contacting
309each name server before giving up. <strong>Default:</strong> <code>4</code></li>
310</ul>
311</li>
312</ul>
313<h4><code>resolver.cancel()</code><span><a class="mark" href="#dns_resolver_cancel" id="dns_resolver_cancel">#</a></span></h4>
314<div class="api_metadata">
315<span>Added in: v8.3.0</span>
316</div>
317<p>Cancel all outstanding DNS queries made by this resolver. The corresponding
318callbacks will be called with an error with code <code>ECANCELLED</code>.</p>
319<h4><code>resolver.setLocalAddress([ipv4][, ipv6])</code><span><a class="mark" href="#dns_resolver_setlocaladdress_ipv4_ipv6" id="dns_resolver_setlocaladdress_ipv4_ipv6">#</a></span></h4>
320<div class="api_metadata">
321<span>Added in: v14.17.0</span>
322</div>
323<ul>
324<li><code>ipv4</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string representation of an IPv4 address.
325<strong>Default:</strong> <code>'0.0.0.0'</code></li>
326<li><code>ipv6</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string representation of an IPv6 address.
327<strong>Default:</strong> <code>'::0'</code></li>
328</ul>
329<p>The resolver instance will send its requests from the specified IP address.
330This allows programs to specify outbound interfaces when used on multi-homed
331systems.</p>
332<p>If a v4 or v6 address is not specified, it is set to the default, and the
333operating system will choose a local address automatically.</p>
334<p>The resolver will use the v4 local address when making requests to IPv4 DNS
335servers, and the v6 local address when making requests to IPv6 DNS servers.
336The <code>rrtype</code> of resolution requests has no impact on the local address used.</p>
337</section><section><h3><code>dns.getServers()</code><span><a class="mark" href="#dns_dns_getservers" id="dns_dns_getservers">#</a></span></h3>
338<div class="api_metadata">
339<span>Added in: v0.11.3</span>
340</div>
341<ul>
342<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
343</ul>
344<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
345that are currently configured for DNS resolution. A string will include a port
346section if a custom port is used.</p>
347<!-- eslint-disable semi-->
348<pre><code class="language-js">[
349  <span class="hljs-string">'4.4.4.4'</span>,
350  <span class="hljs-string">'2001:4860:4860::8888'</span>,
351  <span class="hljs-string">'4.4.4.4:1053'</span>,
352  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
353]</code></pre>
354</section><section><h3><code>dns.lookup(hostname[, options], callback)</code><span><a class="mark" href="#dns_dns_lookup_hostname_options_callback" id="dns_dns_lookup_hostname_options_callback">#</a></span></h3>
355<div class="api_metadata">
356<details class="changelog"><summary>History</summary>
357<table>
358<tbody><tr><th>Version</th><th>Changes</th></tr>
359<tr><td>v8.5.0</td>
360<td><p>The <code>verbatim</code> option is supported now.</p></td></tr>
361<tr><td>v1.2.0</td>
362<td><p>The <code>all</code> option is supported now.</p></td></tr>
363<tr><td>v0.1.90</td>
364<td><p><span>Added in: v0.1.90</span></p></td></tr>
365</tbody></table>
366</details>
367</div>
368<ul>
369<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
370<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
371<ul>
372<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. The value
373<code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong>
374<code>0</code>.</li>
375<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> One or more <a href="#dns_supported_getaddrinfo_flags">supported <code>getaddrinfo</code> flags</a>. Multiple
376flags may be passed by bitwise <code>OR</code>ing their values.</li>
377<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the callback returns all resolved addresses in
378an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
379<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the callback receives IPv4 and IPv6
380addresses in the order the DNS resolver returned them. When <code>false</code>,
381IPv4 addresses are placed before IPv6 addresses.
382<strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is
383expected to change in the not too distant future. Default value is
384configurable using <a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> or
385<a href="cli.html#cli_dns_result_order_order"><code>--dns-result-order</code></a>. New code should use <code>{ verbatim: true }</code>.</li>
386</ul>
387</li>
388<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
389<ul>
390<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
391<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A string representation of an IPv4 or IPv6 address.</li>
392<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <code>4</code> or <code>6</code>, denoting the family of <code>address</code>, or <code>0</code> if
393the address is not an IPv4 or IPv6 address. <code>0</code> is a likely indicator of a
394bug in the name resolution service used by the operating system.</li>
395</ul>
396</li>
397</ul>
398<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or
399AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
400integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided, then IPv4
401and IPv6 addresses are both returned if found.</p>
402<p>With the <code>all</code> option set to <code>true</code>, the arguments for <code>callback</code> change to
403<code>(err, addresses)</code>, with <code>addresses</code> being an array of objects with the
404properties <code>address</code> and <code>family</code>.</p>
405<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.
406Keep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when
407the host name does not exist but also when the lookup fails in other ways
408such as no available file descriptors.</p>
409<p><code>dns.lookup()</code> does not necessarily have anything to do with the DNS protocol.
410The implementation uses an operating system facility that can associate names
411with addresses, and vice versa. This implementation can have subtle but
412important consequences on the behavior of any Node.js program. Please take some
413time to consult the <a href="#dns_implementation_considerations">Implementation considerations section</a> before using
414<code>dns.lookup()</code>.</p>
415<p>Example usage:</p>
416<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>);
417<span class="hljs-keyword">const</span> options = {
418  <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>,
419  <span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<span class="hljs-property">V4MAPPED</span>,
420};
421dns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options, <span class="hljs-function">(<span class="hljs-params">err, address, family</span>) =></span>
422  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'address: %j family: IPv%s'</span>, address, family));
423<span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span>
424
425<span class="hljs-comment">// When options.all is true, the result will be an Array.</span>
426options.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>;
427dns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options, <span class="hljs-function">(<span class="hljs-params">err, addresses</span>) =></span>
428  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'addresses: %j'</span>, addresses));
429<span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]</span></code></pre>
430<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>
431is not set to <code>true</code>, it returns a <code>Promise</code> for an <code>Object</code> with <code>address</code> and
432<code>family</code> properties.</p>
433<h4>Supported getaddrinfo flags<span><a class="mark" href="#dns_supported_getaddrinfo_flags" id="dns_supported_getaddrinfo_flags">#</a></span></h4>
434<div class="api_metadata">
435<details class="changelog"><summary>History</summary>
436<table>
437<tbody><tr><th>Version</th><th>Changes</th></tr>
438<tr><td>v14.0.0</td>
439<td><p>Added support for the <code>dns.ALL</code> flag.</p></td></tr>
440</tbody></table>
441</details>
442</div>
443<p>The following flags can be passed as hints to <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>.</p>
444<ul>
445<li><code>dns.ADDRCONFIG</code>: Limits returned address types to the types of non-loopback
446addresses configured on the system. For example, IPv4 addresses are only
447returned if the current system has at least one IPv4 address configured.</li>
448<li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses were
449found, then return IPv4 mapped IPv6 addresses. It is not supported
450on some operating systems (e.g FreeBSD 10.1).</li>
451<li><code>dns.ALL</code>: If <code>dns.V4MAPPED</code> is specified, return resolved IPv6 addresses as
452well as IPv4 mapped IPv6 addresses.</li>
453</ul>
454</section><section><h3><code>dns.lookupService(address, port, callback)</code><span><a class="mark" href="#dns_dns_lookupservice_address_port_callback" id="dns_dns_lookupservice_address_port_callback">#</a></span></h3>
455<div class="api_metadata">
456<span>Added in: v0.11.14</span>
457</div>
458<ul>
459<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
460<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
461<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
462<ul>
463<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
464<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> e.g. <code>example.com</code></li>
465<li><code>service</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> e.g. <code>http</code></li>
466</ul>
467</li>
468</ul>
469<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
470the operating system's underlying <code>getnameinfo</code> implementation.</p>
471<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
472The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>
473will be thrown.</p>
474<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>
475<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>);
476dns.<span class="hljs-title function_">lookupService</span>(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-number">22</span>, <span class="hljs-function">(<span class="hljs-params">err, hostname, service</span>) =></span> {
477  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(hostname, service);
478  <span class="hljs-comment">// Prints: localhost ssh</span>
479});</code></pre>
480<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
481<code>Promise</code> for an <code>Object</code> with <code>hostname</code> and <code>service</code> properties.</p>
482</section><section><h3><code>dns.resolve(hostname[, rrtype], callback)</code><span><a class="mark" href="#dns_dns_resolve_hostname_rrtype_callback" id="dns_dns_resolve_hostname_rrtype_callback">#</a></span></h3>
483<div class="api_metadata">
484<span>Added in: v0.1.27</span>
485</div>
486<ul>
487<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
488<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Resource record type. <strong>Default:</strong> <code>'A'</code>.</li>
489<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
490<ul>
491<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
492<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
493</ul>
494</li>
495</ul>
496<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array
497of the resource records. The <code>callback</code> function has arguments
498<code>(err, records)</code>. When successful, <code>records</code> will be an array of resource
499records. The type and structure of individual results varies based on <code>rrtype</code>:</p>
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583<table><thead><tr><th><code>rrtype</code></th><th><code>records</code> contains</th><th>Result type</th><th>Shorthand method</th></tr></thead><tbody><tr><td><code>'A'</code></td><td>IPv4 addresses (default)</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dns_resolve4_hostname_options_callback"><code>dns.resolve4()</code></a></td></tr><tr><td><code>'AAAA'</code></td><td>IPv6 addresses</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dns_resolve6_hostname_options_callback"><code>dns.resolve6()</code></a></td></tr><tr><td><code>'ANY'</code></td><td>any records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dns_resolveany_hostname_callback"><code>dns.resolveAny()</code></a></td></tr><tr><td><code>'CAA'</code></td><td>CA authorization records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dns_resolvecaa_hostname_callback"><code>dns.resolveCaa()</code></a></td></tr><tr><td><code>'CNAME'</code></td><td>canonical name records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dns_resolvecname_hostname_callback"><code>dns.resolveCname()</code></a></td></tr><tr><td><code>'MX'</code></td><td>mail exchange records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dns_resolvemx_hostname_callback"><code>dns.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>name authority pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dns_resolvenaptr_hostname_callback"><code>dns.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td>name server records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dns_resolvens_hostname_callback"><code>dns.resolveNs()</code></a></td></tr><tr><td><code>'PTR'</code></td><td>pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dns_resolveptr_hostname_callback"><code>dns.resolvePtr()</code></a></td></tr><tr><td><code>'SOA'</code></td><td>start of authority records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dns_resolvesoa_hostname_callback"><code>dns.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>service records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dns_resolvesrv_hostname_callback"><code>dns.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><td>text records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></td><td><a href="#dns_dns_resolvetxt_hostname_callback"><code>dns.resolveTxt()</code></a></td></tr></tbody></table>
584<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
585<a href="#dns_error_codes">DNS error codes</a>.</p>
586</section><section><h3><code>dns.resolve4(hostname[, options], callback)</code><span><a class="mark" href="#dns_dns_resolve4_hostname_options_callback" id="dns_dns_resolve4_hostname_options_callback">#</a></span></h3>
587<div class="api_metadata">
588<details class="changelog"><summary>History</summary>
589<table>
590<tbody><tr><th>Version</th><th>Changes</th></tr>
591<tr><td>v7.2.0</td>
592<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p></td></tr>
593<tr><td>v0.1.16</td>
594<td><p><span>Added in: v0.1.16</span></p></td></tr>
595</tbody></table>
596</details>
597</div>
598<ul>
599<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
600<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
601<ul>
602<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
603When <code>true</code>, the callback receives an array of
604<code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings,
605with the TTL expressed in seconds.</li>
606</ul>
607</li>
608<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
609<ul>
610<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
611<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
612</ul>
613</li>
614</ul>
615<p>Uses the DNS protocol to resolve a IPv4 addresses (<code>A</code> records) for the
616<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function
617will contain an array of IPv4 addresses (e.g.
618<code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>
619</section><section><h3><code>dns.resolve6(hostname[, options], callback)</code><span><a class="mark" href="#dns_dns_resolve6_hostname_options_callback" id="dns_dns_resolve6_hostname_options_callback">#</a></span></h3>
620<div class="api_metadata">
621<details class="changelog"><summary>History</summary>
622<table>
623<tbody><tr><th>Version</th><th>Changes</th></tr>
624<tr><td>v7.2.0</td>
625<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p></td></tr>
626<tr><td>v0.1.16</td>
627<td><p><span>Added in: v0.1.16</span></p></td></tr>
628</tbody></table>
629</details>
630</div>
631<ul>
632<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
633<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
634<ul>
635<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
636When <code>true</code>, the callback receives an array of
637<code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of
638strings, with the TTL expressed in seconds.</li>
639</ul>
640</li>
641<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
642<ul>
643<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
644<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
645</ul>
646</li>
647</ul>
648<p>Uses the DNS protocol to resolve a IPv6 addresses (<code>AAAA</code> records) for the
649<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function
650will contain an array of IPv6 addresses.</p>
651</section><section><h3><code>dns.resolveAny(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolveany_hostname_callback" id="dns_dns_resolveany_hostname_callback">#</a></span></h3>
652<ul>
653<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
654<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
655<ul>
656<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
657<li><code>ret</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
658</ul>
659</li>
660</ul>
661<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).
662The <code>ret</code> argument passed to the <code>callback</code> function will be an array containing
663various types of records. Each object has a property <code>type</code> that indicates the
664type of the current record. And depending on the <code>type</code>, additional properties
665will be present on the object:</p>
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715<table><thead><tr><th>Type</th><th>Properties</th></tr></thead><tbody><tr><td><code>'A'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'AAAA'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'CNAME'</code></td><td><code>value</code></td></tr><tr><td><code>'MX'</code></td><td>Refer to <a href="#dns_dns_resolvemx_hostname_callback"><code>dns.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>Refer to <a href="#dns_dns_resolvenaptr_hostname_callback"><code>dns.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td><code>value</code></td></tr><tr><td><code>'PTR'</code></td><td><code>value</code></td></tr><tr><td><code>'SOA'</code></td><td>Refer to <a href="#dns_dns_resolvesoa_hostname_callback"><code>dns.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>Refer to <a href="#dns_dns_resolvesrv_hostname_callback"><code>dns.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><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></tr></tbody></table>
716<p>Here is an example of the <code>ret</code> object passed to the callback:</p>
717<!-- eslint-disable semi -->
718<pre><code class="language-js">[ { <span class="hljs-attr">type</span>: <span class="hljs-string">'A'</span>, <span class="hljs-attr">address</span>: <span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-attr">ttl</span>: <span class="hljs-number">299</span> },
719  { <span class="hljs-attr">type</span>: <span class="hljs-string">'CNAME'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'example.com'</span> },
720  { <span class="hljs-attr">type</span>: <span class="hljs-string">'MX'</span>, <span class="hljs-attr">exchange</span>: <span class="hljs-string">'alt4.aspmx.l.example.com'</span>, <span class="hljs-attr">priority</span>: <span class="hljs-number">50</span> },
721  { <span class="hljs-attr">type</span>: <span class="hljs-string">'NS'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'ns1.example.com'</span> },
722  { <span class="hljs-attr">type</span>: <span class="hljs-string">'TXT'</span>, <span class="hljs-attr">entries</span>: [ <span class="hljs-string">'v=spf1 include:_spf.example.com ~all'</span> ] },
723  { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>,
724    <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>,
725    <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>,
726    <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>,
727    <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>,
728    <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>,
729    <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>,
730    <span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code></pre>
731<p>DNS server operators may choose not to respond to <code>ANY</code>
732queries. It may be better to call individual methods like <a href="#dns_dns_resolve4_hostname_options_callback"><code>dns.resolve4()</code></a>,
733<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>
734</section><section><h3><code>dns.resolveCname(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvecname_hostname_callback" id="dns_dns_resolvecname_hostname_callback">#</a></span></h3>
735<div class="api_metadata">
736<span>Added in: v0.3.2</span>
737</div>
738<ul>
739<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
740<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
741<ul>
742<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
743<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
744</ul>
745</li>
746</ul>
747<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. The
748<code>addresses</code> argument passed to the <code>callback</code> function
749will contain an array of canonical name records available for the <code>hostname</code>
750(e.g. <code>['bar.example.com']</code>).</p>
751</section><section><h3><code>dns.resolveCaa(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvecaa_hostname_callback" id="dns_dns_resolvecaa_hostname_callback">#</a></span></h3>
752<div class="api_metadata">
753<span>Added in: v14.17.0</span>
754</div>
755<ul>
756<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
757<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
758<ul>
759<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
760<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
761</ul>
762</li>
763</ul>
764<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. The
765<code>addresses</code> argument passed to the <code>callback</code> function
766will contain an array of certification authority authorization records
767available for the <code>hostname</code> (e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]</code>).</p>
768</section><section><h3><code>dns.resolveMx(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvemx_hostname_callback" id="dns_dns_resolvemx_hostname_callback">#</a></span></h3>
769<div class="api_metadata">
770<span>Added in: v0.1.27</span>
771</div>
772<ul>
773<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
774<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
775<ul>
776<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
777<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
778</ul>
779</li>
780</ul>
781<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
782<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
783contain an array of objects containing both a <code>priority</code> and <code>exchange</code>
784property (e.g. <code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>
785</section><section><h3><code>dns.resolveNaptr(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvenaptr_hostname_callback" id="dns_dns_resolvenaptr_hostname_callback">#</a></span></h3>
786<div class="api_metadata">
787<span>Added in: v0.9.12</span>
788</div>
789<ul>
790<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
791<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
792<ul>
793<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
794<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
795</ul>
796</li>
797</ul>
798<p>Uses the DNS protocol to resolve regular expression based records (<code>NAPTR</code>
799records) for the <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code>
800function will contain an array of objects with the following properties:</p>
801<ul>
802<li><code>flags</code></li>
803<li><code>service</code></li>
804<li><code>regexp</code></li>
805<li><code>replacement</code></li>
806<li><code>order</code></li>
807<li><code>preference</code></li>
808</ul>
809<!-- eslint-skip -->
810<pre><code class="language-js">{
811  <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>,
812  <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>,
813  <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>,
814  <span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</span>,
815  <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>,
816  <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span>
817}</code></pre>
818</section><section><h3><code>dns.resolveNs(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvens_hostname_callback" id="dns_dns_resolvens_hostname_callback">#</a></span></h3>
819<div class="api_metadata">
820<span>Added in: v0.1.90</span>
821</div>
822<ul>
823<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
824<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
825<ul>
826<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
827<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
828</ul>
829</li>
830</ul>
831<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
832<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
833contain an array of name server records available for <code>hostname</code>
834(e.g. <code>['ns1.example.com', 'ns2.example.com']</code>).</p>
835</section><section><h3><code>dns.resolvePtr(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolveptr_hostname_callback" id="dns_dns_resolveptr_hostname_callback">#</a></span></h3>
836<div class="api_metadata">
837<span>Added in: v6.0.0</span>
838</div>
839<ul>
840<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
841<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
842<ul>
843<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
844<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
845</ul>
846</li>
847</ul>
848<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
849<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
850be an array of strings containing the reply records.</p>
851</section><section><h3><code>dns.resolveSoa(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvesoa_hostname_callback" id="dns_dns_resolvesoa_hostname_callback">#</a></span></h3>
852<div class="api_metadata">
853<span>Added in: v0.11.10</span>
854</div>
855<ul>
856<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
857<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
858<ul>
859<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
860<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
861</ul>
862</li>
863</ul>
864<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
865the <code>hostname</code>. The <code>address</code> argument passed to the <code>callback</code> function will
866be an object with the following properties:</p>
867<ul>
868<li><code>nsname</code></li>
869<li><code>hostmaster</code></li>
870<li><code>serial</code></li>
871<li><code>refresh</code></li>
872<li><code>retry</code></li>
873<li><code>expire</code></li>
874<li><code>minttl</code></li>
875</ul>
876<!-- eslint-skip -->
877<pre><code class="language-js">{
878  <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>,
879  <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>,
880  <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>,
881  <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>,
882  <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>,
883  <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>,
884  <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span>
885}</code></pre>
886</section><section><h3><code>dns.resolveSrv(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvesrv_hostname_callback" id="dns_dns_resolvesrv_hostname_callback">#</a></span></h3>
887<div class="api_metadata">
888<span>Added in: v0.1.27</span>
889</div>
890<ul>
891<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
892<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
893<ul>
894<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
895<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object[]></a></li>
896</ul>
897</li>
898</ul>
899<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
900<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
901be an array of objects with the following properties:</p>
902<ul>
903<li><code>priority</code></li>
904<li><code>weight</code></li>
905<li><code>port</code></li>
906<li><code>name</code></li>
907</ul>
908<!-- eslint-skip -->
909<pre><code class="language-js">{
910  <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>,
911  <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>,
912  <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>,
913  <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span>
914}</code></pre>
915</section><section><h3><code>dns.resolveTxt(hostname, callback)</code><span><a class="mark" href="#dns_dns_resolvetxt_hostname_callback" id="dns_dns_resolvetxt_hostname_callback">#</a></span></h3>
916<div class="api_metadata">
917<span>Added in: v0.1.27</span>
918</div>
919<!--lint disable no-undefined-references list-item-bullet-indent-->
920<ul>
921<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
922<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
923<ul>
924<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
925<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[][]></a></li>
926</ul>
927</li>
928</ul>
929<!--lint enable no-undefined-references list-item-bullet-indent-->
930<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
931<code>hostname</code>. The <code>records</code> argument passed to the <code>callback</code> function is a
932two-dimensional array of the text records available for <code>hostname</code> (e.g.
933<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of
934one record. Depending on the use case, these could be either joined together or
935treated separately.</p>
936</section><section><h3><code>dns.reverse(ip, callback)</code><span><a class="mark" href="#dns_dns_reverse_ip_callback" id="dns_dns_reverse_ip_callback">#</a></span></h3>
937<div class="api_metadata">
938<span>Added in: v0.1.16</span>
939</div>
940<ul>
941<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
942<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
943<ul>
944<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a></li>
945<li><code>hostnames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
946</ul>
947</li>
948</ul>
949<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
950array of host names.</p>
951<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
952one of the <a href="#dns_error_codes">DNS error codes</a>.</p>
953</section><section><h3><code>dns.setDefaultResultOrder(order)</code><span><a class="mark" href="#dns_dns_setdefaultresultorder_order" id="dns_dns_setdefaultresultorder_order">#</a></span></h3>
954<div class="api_metadata">
955<span>Added in: v14.18.0</span>
956</div>
957<ul>
958<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> must be <code>'ipv4first'</code> or <code>'verbatim'</code>.</li>
959</ul>
960<p>Set the default value of <code>verbatim</code> in <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> and
961<a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
962<ul>
963<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
964<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
965</ul>
966<p>The default is <code>ipv4first</code> and <a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> have higher
967priority than <a href="cli.html#cli_dns_result_order_order"><code>--dns-result-order</code></a>. When using <a href="worker_threads.html">worker threads</a>,
968<a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> from the main thread won't affect the default
969dns orders in workers.</p>
970</section><section><h3><code>dns.setServers(servers)</code><span><a class="mark" href="#dns_dns_setservers_servers" id="dns_dns_setservers_servers">#</a></span></h3>
971<div class="api_metadata">
972<span>Added in: v0.11.3</span>
973</div>
974<ul>
975<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li>
976</ul>
977<p>Sets the IP address and port of servers to be used when performing DNS
978resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted
979addresses. If the port is the IANA default DNS port (53) it can be omitted.</p>
980<pre><code class="language-js">dns.<span class="hljs-title function_">setServers</span>([
981  <span class="hljs-string">'4.4.4.4'</span>,
982  <span class="hljs-string">'[2001:4860:4860::8888]'</span>,
983  <span class="hljs-string">'4.4.4.4:1053'</span>,
984  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
985]);</code></pre>
986<p>An error will be thrown if an invalid address is provided.</p>
987<p>The <code>dns.setServers()</code> method must not be called while a DNS query is in
988progress.</p>
989<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>,
990<code>dns.resolve*()</code> and <a href="#dns_dns_reverse_ip_callback"><code>dns.reverse()</code></a> (and specifically <em>not</em>
991<a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>).</p>
992<p>This method works much like
993<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
994That is, if attempting to resolve with the first server provided results in a
995<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with
996subsequent servers provided. Fallback DNS servers will only be used if the
997earlier ones time out or result in some other error.</p>
998</section><section><h3>DNS promises API<span><a class="mark" href="#dns_dns_promises_api" id="dns_dns_promises_api">#</a></span></h3>
999<div class="api_metadata">
1000<details class="changelog"><summary>History</summary>
1001<table>
1002<tbody><tr><th>Version</th><th>Changes</th></tr>
1003<tr><td>v11.14.0, v10.17.0</td>
1004<td><p>This API is no longer experimental.</p></td></tr>
1005<tr><td>v10.6.0</td>
1006<td><p><span>Added in: v10.6.0</span></p></td></tr>
1007</tbody></table>
1008</details>
1009</div>
1010<p>The <code>dns.promises</code> API provides an alternative set of asynchronous DNS methods
1011that return <code>Promise</code> objects rather than using callbacks. The API is accessible
1012via <code>require('dns').promises</code>.</p>
1013<h4>Class: <code>dnsPromises.Resolver</code><span><a class="mark" href="#dns_class_dnspromises_resolver" id="dns_class_dnspromises_resolver">#</a></span></h4>
1014<div class="api_metadata">
1015<span>Added in: v10.6.0</span>
1016</div>
1017<p>An independent resolver for DNS requests.</p>
1018<p>Creating a new resolver uses the default server settings. Setting
1019the servers used for a resolver using
1020<a href="#dns_dnspromises_setservers_servers"><code>resolver.setServers()</code></a> does not affect
1021other resolvers:</p>
1022<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">Resolver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>).<span class="hljs-property">promises</span>;
1023<span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Resolver</span>();
1024resolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'</span>]);
1025
1026<span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global settings.</span>
1027resolver.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">addresses</span>) =></span> {
1028  <span class="hljs-comment">// ...</span>
1029});
1030
1031<span class="hljs-comment">// Alternatively, the same code can be written using async-await style.</span>
1032(<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) {
1033  <span class="hljs-keyword">const</span> addresses = <span class="hljs-keyword">await</span> resolver.<span class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>);
1034})();</code></pre>
1035<p>The following methods from the <code>dnsPromises</code> API are available:</p>
1036<ul>
1037<li><a href="#dns_dnspromises_getservers"><code>resolver.getServers()</code></a></li>
1038<li><a href="#dns_dnspromises_resolve_hostname_rrtype"><code>resolver.resolve()</code></a></li>
1039<li><a href="#dns_dnspromises_resolve4_hostname_options"><code>resolver.resolve4()</code></a></li>
1040<li><a href="#dns_dnspromises_resolve6_hostname_options"><code>resolver.resolve6()</code></a></li>
1041<li><a href="#dns_dnspromises_resolveany_hostname"><code>resolver.resolveAny()</code></a></li>
1042<li><a href="#dns_dnspromises_resolvecaa_hostname"><code>resolver.resolveCaa()</code></a></li>
1043<li><a href="#dns_dnspromises_resolvecname_hostname"><code>resolver.resolveCname()</code></a></li>
1044<li><a href="#dns_dnspromises_resolvemx_hostname"><code>resolver.resolveMx()</code></a></li>
1045<li><a href="#dns_dnspromises_resolvenaptr_hostname"><code>resolver.resolveNaptr()</code></a></li>
1046<li><a href="#dns_dnspromises_resolvens_hostname"><code>resolver.resolveNs()</code></a></li>
1047<li><a href="#dns_dnspromises_resolveptr_hostname"><code>resolver.resolvePtr()</code></a></li>
1048<li><a href="#dns_dnspromises_resolvesoa_hostname"><code>resolver.resolveSoa()</code></a></li>
1049<li><a href="#dns_dnspromises_resolvesrv_hostname"><code>resolver.resolveSrv()</code></a></li>
1050<li><a href="#dns_dnspromises_resolvetxt_hostname"><code>resolver.resolveTxt()</code></a></li>
1051<li><a href="#dns_dnspromises_reverse_ip"><code>resolver.reverse()</code></a></li>
1052<li><a href="#dns_dnspromises_setservers_servers"><code>resolver.setServers()</code></a></li>
1053</ul>
1054<h4><code>resolver.cancel()</code><span><a class="mark" href="#dns_resolver_cancel_1" id="dns_resolver_cancel_1">#</a></span></h4>
1055<div class="api_metadata">
1056<span>Added in: v14.17.0</span>
1057</div>
1058<p>Cancel all outstanding DNS queries made by this resolver. The corresponding
1059promises will be rejected with an error with code <code>ECANCELLED</code>.</p>
1060<h4><code>dnsPromises.getServers()</code><span><a class="mark" href="#dns_dnspromises_getservers" id="dns_dnspromises_getservers">#</a></span></h4>
1061<div class="api_metadata">
1062<span>Added in: v10.6.0</span>
1063</div>
1064<ul>
1065<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
1066</ul>
1067<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
1068that are currently configured for DNS resolution. A string will include a port
1069section if a custom port is used.</p>
1070<!-- eslint-disable semi-->
1071<pre><code class="language-js">[
1072  <span class="hljs-string">'4.4.4.4'</span>,
1073  <span class="hljs-string">'2001:4860:4860::8888'</span>,
1074  <span class="hljs-string">'4.4.4.4:1053'</span>,
1075  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
1076]</code></pre>
1077<h4><code>dnsPromises.lookup(hostname[, options])</code><span><a class="mark" href="#dns_dnspromises_lookup_hostname_options" id="dns_dnspromises_lookup_hostname_options">#</a></span></h4>
1078<div class="api_metadata">
1079<span>Added in: v10.6.0</span>
1080</div>
1081<ul>
1082<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1083<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1084<ul>
1085<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. The value
1086<code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong>
1087<code>0</code>.</li>
1088<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> One or more <a href="#dns_supported_getaddrinfo_flags">supported <code>getaddrinfo</code> flags</a>. Multiple
1089flags may be passed by bitwise <code>OR</code>ing their values.</li>
1090<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the <code>Promise</code> is resolved with all addresses in
1091an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
1092<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the <code>Promise</code> is resolved with IPv4 and
1093IPv6 addresses in the order the DNS resolver returned them. When <code>false</code>,
1094IPv4 addresses are placed before IPv6 addresses.
1095<strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is
1096expected to change in the not too distant future. Default value is
1097configurable using <a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> or
1098<a href="cli.html#cli_dns_result_order_order"><code>--dns-result-order</code></a>. New code should use <code>{ verbatim: true }</code>.</li>
1099</ul>
1100</li>
1101</ul>
1102<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or
1103AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
1104integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided, then IPv4
1105and IPv6 addresses are both returned if found.</p>
1106<p>With the <code>all</code> option set to <code>true</code>, the <code>Promise</code> is resolved with <code>addresses</code>
1107being an array of objects with the properties <code>address</code> and <code>family</code>.</p>
1108<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>
1109is the error code.
1110Keep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when
1111the host name does not exist but also when the lookup fails in other ways
1112such as no available file descriptors.</p>
1113<p><a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup()</code></a> does not necessarily have anything to do with the DNS
1114protocol. The implementation uses an operating system facility that can
1115associate names with addresses, and vice versa. This implementation can have
1116subtle but important consequences on the behavior of any Node.js program. Please
1117take some time to consult the <a href="#dns_implementation_considerations">Implementation considerations section</a> before
1118using <code>dnsPromises.lookup()</code>.</p>
1119<p>Example usage:</p>
1120<pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>);
1121<span class="hljs-keyword">const</span> dnsPromises = dns.<span class="hljs-property">promises</span>;
1122<span class="hljs-keyword">const</span> options = {
1123  <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>,
1124  <span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<span class="hljs-property">V4MAPPED</span>,
1125};
1126
1127dnsPromises.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">result</span>) =></span> {
1128  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'address: %j family: IPv%s'</span>, result.<span class="hljs-property">address</span>, result.<span class="hljs-property">family</span>);
1129  <span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span>
1130});
1131
1132<span class="hljs-comment">// When options.all is true, the result will be an Array.</span>
1133options.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>;
1134dnsPromises.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">result</span>) =></span> {
1135  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'addresses: %j'</span>, result);
1136  <span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]</span>
1137});</code></pre>
1138<h4><code>dnsPromises.lookupService(address, port)</code><span><a class="mark" href="#dns_dnspromises_lookupservice_address_port" id="dns_dnspromises_lookupservice_address_port">#</a></span></h4>
1139<div class="api_metadata">
1140<span>Added in: v10.6.0</span>
1141</div>
1142<ul>
1143<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1144<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1145</ul>
1146<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
1147the operating system's underlying <code>getnameinfo</code> implementation.</p>
1148<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
1149The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>
1150will be thrown.</p>
1151<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>
1152is the error code.</p>
1153<pre><code class="language-js"><span class="hljs-keyword">const</span> dnsPromises = <span class="hljs-built_in">require</span>(<span class="hljs-string">'dns'</span>).<span class="hljs-property">promises</span>;
1154dnsPromises.<span class="hljs-title function_">lookupService</span>(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-number">22</span>).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">result</span>) =></span> {
1155  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(result.<span class="hljs-property">hostname</span>, result.<span class="hljs-property">service</span>);
1156  <span class="hljs-comment">// Prints: localhost ssh</span>
1157});</code></pre>
1158<h4><code>dnsPromises.resolve(hostname[, rrtype])</code><span><a class="mark" href="#dns_dnspromises_resolve_hostname_rrtype" id="dns_dnspromises_resolve_hostname_rrtype">#</a></span></h4>
1159<div class="api_metadata">
1160<span>Added in: v10.6.0</span>
1161</div>
1162<ul>
1163<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
1164<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Resource record type. <strong>Default:</strong> <code>'A'</code>.</li>
1165</ul>
1166<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array
1167of the resource records. When successful, the <code>Promise</code> is resolved with an
1168array of resource records. The type and structure of individual results vary
1169based on <code>rrtype</code>:</p>
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253<table><thead><tr><th><code>rrtype</code></th><th><code>records</code> contains</th><th>Result type</th><th>Shorthand method</th></tr></thead><tbody><tr><td><code>'A'</code></td><td>IPv4 addresses (default)</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dnspromises_resolve4_hostname_options"><code>dnsPromises.resolve4()</code></a></td></tr><tr><td><code>'AAAA'</code></td><td>IPv6 addresses</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dnspromises_resolve6_hostname_options"><code>dnsPromises.resolve6()</code></a></td></tr><tr><td><code>'ANY'</code></td><td>any records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dnspromises_resolveany_hostname"><code>dnsPromises.resolveAny()</code></a></td></tr><tr><td><code>'CAA'</code></td><td>CA authorization records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dnspromises_resolvecaa_hostname"><code>dnsPromises.resolveCaa()</code></a></td></tr><tr><td><code>'CNAME'</code></td><td>canonical name records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dnspromises_resolvecname_hostname"><code>dnsPromises.resolveCname()</code></a></td></tr><tr><td><code>'MX'</code></td><td>mail exchange records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dnspromises_resolvemx_hostname"><code>dnsPromises.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>name authority pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dnspromises_resolvenaptr_hostname"><code>dnsPromises.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td>name server records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dnspromises_resolvens_hostname"><code>dnsPromises.resolveNs()</code></a></td></tr><tr><td><code>'PTR'</code></td><td>pointer records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></td><td><a href="#dns_dnspromises_resolveptr_hostname"><code>dnsPromises.resolvePtr()</code></a></td></tr><tr><td><code>'SOA'</code></td><td>start of authority records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dnspromises_resolvesoa_hostname"><code>dnsPromises.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>service records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></td><td><a href="#dns_dnspromises_resolvesrv_hostname"><code>dnsPromises.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><td>text records</td><td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></td><td><a href="#dns_dnspromises_resolvetxt_hostname"><code>dnsPromises.resolveTxt()</code></a></td></tr></tbody></table>
1254<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>
1255is one of the <a href="#dns_error_codes">DNS error codes</a>.</p>
1256<h4><code>dnsPromises.resolve4(hostname[, options])</code><span><a class="mark" href="#dns_dnspromises_resolve4_hostname_options" id="dns_dnspromises_resolve4_hostname_options">#</a></span></h4>
1257<div class="api_metadata">
1258<span>Added in: v10.6.0</span>
1259</div>
1260<ul>
1261<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
1262<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1263<ul>
1264<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
1265When <code>true</code>, the <code>Promise</code> is resolved with an array of
1266<code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings,
1267with the TTL expressed in seconds.</li>
1268</ul>
1269</li>
1270</ul>
1271<p>Uses the DNS protocol to resolve IPv4 addresses (<code>A</code> records) for the
1272<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv4
1273addresses (e.g. <code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>
1274<h4><code>dnsPromises.resolve6(hostname[, options])</code><span><a class="mark" href="#dns_dnspromises_resolve6_hostname_options" id="dns_dnspromises_resolve6_hostname_options">#</a></span></h4>
1275<div class="api_metadata">
1276<span>Added in: v10.6.0</span>
1277</div>
1278<ul>
1279<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Host name to resolve.</li>
1280<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1281<ul>
1282<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Retrieve the Time-To-Live value (TTL) of each record.
1283When <code>true</code>, the <code>Promise</code> is resolved with an array of
1284<code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of
1285strings, with the TTL expressed in seconds.</li>
1286</ul>
1287</li>
1288</ul>
1289<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
1290<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv6
1291addresses.</p>
1292<h4><code>dnsPromises.resolveAny(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolveany_hostname" id="dns_dnspromises_resolveany_hostname">#</a></span></h4>
1293<div class="api_metadata">
1294<span>Added in: v10.6.0</span>
1295</div>
1296<ul>
1297<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1298</ul>
1299<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).
1300On success, the <code>Promise</code> is resolved with an array containing various types of
1301records. Each object has a property <code>type</code> that indicates the type of the
1302current record. And depending on the <code>type</code>, additional properties will be
1303present on the object:</p>
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353<table><thead><tr><th>Type</th><th>Properties</th></tr></thead><tbody><tr><td><code>'A'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'AAAA'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'CNAME'</code></td><td><code>value</code></td></tr><tr><td><code>'MX'</code></td><td>Refer to <a href="#dns_dnspromises_resolvemx_hostname"><code>dnsPromises.resolveMx()</code></a></td></tr><tr><td><code>'NAPTR'</code></td><td>Refer to <a href="#dns_dnspromises_resolvenaptr_hostname"><code>dnsPromises.resolveNaptr()</code></a></td></tr><tr><td><code>'NS'</code></td><td><code>value</code></td></tr><tr><td><code>'PTR'</code></td><td><code>value</code></td></tr><tr><td><code>'SOA'</code></td><td>Refer to <a href="#dns_dnspromises_resolvesoa_hostname"><code>dnsPromises.resolveSoa()</code></a></td></tr><tr><td><code>'SRV'</code></td><td>Refer to <a href="#dns_dnspromises_resolvesrv_hostname"><code>dnsPromises.resolveSrv()</code></a></td></tr><tr><td><code>'TXT'</code></td><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></tr></tbody></table>
1354<p>Here is an example of the result object:</p>
1355<!-- eslint-disable semi -->
1356<pre><code class="language-js">[ { <span class="hljs-attr">type</span>: <span class="hljs-string">'A'</span>, <span class="hljs-attr">address</span>: <span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-attr">ttl</span>: <span class="hljs-number">299</span> },
1357  { <span class="hljs-attr">type</span>: <span class="hljs-string">'CNAME'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'example.com'</span> },
1358  { <span class="hljs-attr">type</span>: <span class="hljs-string">'MX'</span>, <span class="hljs-attr">exchange</span>: <span class="hljs-string">'alt4.aspmx.l.example.com'</span>, <span class="hljs-attr">priority</span>: <span class="hljs-number">50</span> },
1359  { <span class="hljs-attr">type</span>: <span class="hljs-string">'NS'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'ns1.example.com'</span> },
1360  { <span class="hljs-attr">type</span>: <span class="hljs-string">'TXT'</span>, <span class="hljs-attr">entries</span>: [ <span class="hljs-string">'v=spf1 include:_spf.example.com ~all'</span> ] },
1361  { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>,
1362    <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>,
1363    <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>,
1364    <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>,
1365    <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>,
1366    <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>,
1367    <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>,
1368    <span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code></pre>
1369<h4><code>dnsPromises.resolveCaa(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvecaa_hostname" id="dns_dnspromises_resolvecaa_hostname">#</a></span></h4>
1370<div class="api_metadata">
1371<span>Added in: v14.17.0</span>
1372</div>
1373<ul>
1374<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1375</ul>
1376<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. On success,
1377the <code>Promise</code> is resolved with an array of objects containing available
1378certification authority authorization records available for the <code>hostname</code>
1379(e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]</code>).</p>
1380<h4><code>dnsPromises.resolveCname(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvecname_hostname" id="dns_dnspromises_resolvecname_hostname">#</a></span></h4>
1381<div class="api_metadata">
1382<span>Added in: v10.6.0</span>
1383</div>
1384<ul>
1385<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1386</ul>
1387<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. On success,
1388the <code>Promise</code> is resolved with an array of canonical name records available for
1389the <code>hostname</code> (e.g. <code>['bar.example.com']</code>).</p>
1390<h4><code>dnsPromises.resolveMx(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvemx_hostname" id="dns_dnspromises_resolvemx_hostname">#</a></span></h4>
1391<div class="api_metadata">
1392<span>Added in: v10.6.0</span>
1393</div>
1394<ul>
1395<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1396</ul>
1397<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
1398<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects
1399containing both a <code>priority</code> and <code>exchange</code> property (e.g.
1400<code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>
1401<h4><code>dnsPromises.resolveNaptr(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvenaptr_hostname" id="dns_dnspromises_resolvenaptr_hostname">#</a></span></h4>
1402<div class="api_metadata">
1403<span>Added in: v10.6.0</span>
1404</div>
1405<ul>
1406<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1407</ul>
1408<p>Uses the DNS protocol to resolve regular expression based records (<code>NAPTR</code>
1409records) for the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array
1410of objects with the following properties:</p>
1411<ul>
1412<li><code>flags</code></li>
1413<li><code>service</code></li>
1414<li><code>regexp</code></li>
1415<li><code>replacement</code></li>
1416<li><code>order</code></li>
1417<li><code>preference</code></li>
1418</ul>
1419<!-- eslint-skip -->
1420<pre><code class="language-js">{
1421  <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>,
1422  <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>,
1423  <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>,
1424  <span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</span>,
1425  <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>,
1426  <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span>
1427}</code></pre>
1428<h4><code>dnsPromises.resolveNs(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvens_hostname" id="dns_dnspromises_resolvens_hostname">#</a></span></h4>
1429<div class="api_metadata">
1430<span>Added in: v10.6.0</span>
1431</div>
1432<ul>
1433<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1434</ul>
1435<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
1436<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of name server
1437records available for <code>hostname</code> (e.g.
1438<code>['ns1.example.com', 'ns2.example.com']</code>).</p>
1439<h4><code>dnsPromises.resolvePtr(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolveptr_hostname" id="dns_dnspromises_resolveptr_hostname">#</a></span></h4>
1440<div class="api_metadata">
1441<span>Added in: v10.6.0</span>
1442</div>
1443<ul>
1444<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1445</ul>
1446<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
1447<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of strings
1448containing the reply records.</p>
1449<h4><code>dnsPromises.resolveSoa(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvesoa_hostname" id="dns_dnspromises_resolvesoa_hostname">#</a></span></h4>
1450<div class="api_metadata">
1451<span>Added in: v10.6.0</span>
1452</div>
1453<ul>
1454<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1455</ul>
1456<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
1457the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an object with the
1458following properties:</p>
1459<ul>
1460<li><code>nsname</code></li>
1461<li><code>hostmaster</code></li>
1462<li><code>serial</code></li>
1463<li><code>refresh</code></li>
1464<li><code>retry</code></li>
1465<li><code>expire</code></li>
1466<li><code>minttl</code></li>
1467</ul>
1468<!-- eslint-skip -->
1469<pre><code class="language-js">{
1470  <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>,
1471  <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>,
1472  <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>,
1473  <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>,
1474  <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>,
1475  <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>,
1476  <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span>
1477}</code></pre>
1478<h4><code>dnsPromises.resolveSrv(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvesrv_hostname" id="dns_dnspromises_resolvesrv_hostname">#</a></span></h4>
1479<div class="api_metadata">
1480<span>Added in: v10.6.0</span>
1481</div>
1482<ul>
1483<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1484</ul>
1485<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
1486<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects with
1487the following properties:</p>
1488<ul>
1489<li><code>priority</code></li>
1490<li><code>weight</code></li>
1491<li><code>port</code></li>
1492<li><code>name</code></li>
1493</ul>
1494<!-- eslint-skip -->
1495<pre><code class="language-js">{
1496  <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>,
1497  <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>,
1498  <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>,
1499  <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span>
1500}</code></pre>
1501<h4><code>dnsPromises.resolveTxt(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvetxt_hostname" id="dns_dnspromises_resolvetxt_hostname">#</a></span></h4>
1502<div class="api_metadata">
1503<span>Added in: v10.6.0</span>
1504</div>
1505<ul>
1506<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1507</ul>
1508<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
1509<code>hostname</code>. On success, the <code>Promise</code> is resolved with a two-dimensional array
1510of the text records available for <code>hostname</code> (e.g.
1511<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of
1512one record. Depending on the use case, these could be either joined together or
1513treated separately.</p>
1514<h4><code>dnsPromises.reverse(ip)</code><span><a class="mark" href="#dns_dnspromises_reverse_ip" id="dns_dnspromises_reverse_ip">#</a></span></h4>
1515<div class="api_metadata">
1516<span>Added in: v10.6.0</span>
1517</div>
1518<ul>
1519<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1520</ul>
1521<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
1522array of host names.</p>
1523<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>
1524is one of the <a href="#dns_error_codes">DNS error codes</a>.</p>
1525<h4><code>dnsPromises.setDefaultResultOrder(order)</code><span><a class="mark" href="#dns_dnspromises_setdefaultresultorder_order" id="dns_dnspromises_setdefaultresultorder_order">#</a></span></h4>
1526<div class="api_metadata">
1527<span>Added in: v14.18.0</span>
1528</div>
1529<ul>
1530<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> must be <code>'ipv4first'</code> or <code>'verbatim'</code>.</li>
1531</ul>
1532<p>Set the default value of <code>verbatim</code> in <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> and
1533<a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
1534<ul>
1535<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
1536<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
1537</ul>
1538<p>The default is <code>ipv4first</code> and <a href="#dns_dnspromises_setdefaultresultorder_order"><code>dnsPromises.setDefaultResultOrder()</code></a> have
1539higher priority than <a href="cli.html#cli_dns_result_order_order"><code>--dns-result-order</code></a>. When using <a href="worker_threads.html">worker threads</a>,
1540<a href="#dns_dnspromises_setdefaultresultorder_order"><code>dnsPromises.setDefaultResultOrder()</code></a> from the main thread won't affect the
1541default dns orders in workers.</p>
1542<h4><code>dnsPromises.setServers(servers)</code><span><a class="mark" href="#dns_dnspromises_setservers_servers" id="dns_dnspromises_setservers_servers">#</a></span></h4>
1543<div class="api_metadata">
1544<span>Added in: v10.6.0</span>
1545</div>
1546<ul>
1547<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li>
1548</ul>
1549<p>Sets the IP address and port of servers to be used when performing DNS
1550resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted
1551addresses. If the port is the IANA default DNS port (53) it can be omitted.</p>
1552<pre><code class="language-js">dnsPromises.<span class="hljs-title function_">setServers</span>([
1553  <span class="hljs-string">'4.4.4.4'</span>,
1554  <span class="hljs-string">'[2001:4860:4860::8888]'</span>,
1555  <span class="hljs-string">'4.4.4.4:1053'</span>,
1556  <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
1557]);</code></pre>
1558<p>An error will be thrown if an invalid address is provided.</p>
1559<p>The <code>dnsPromises.setServers()</code> method must not be called while a DNS query is in
1560progress.</p>
1561<p>This method works much like
1562<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
1563That is, if attempting to resolve with the first server provided results in a
1564<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with
1565subsequent servers provided. Fallback DNS servers will only be used if the
1566earlier ones time out or result in some other error.</p>
1567</section><section><h3>Error codes<span><a class="mark" href="#dns_error_codes" id="dns_error_codes">#</a></span></h3>
1568<p>Each DNS query can return one of the following error codes:</p>
1569<ul>
1570<li><code>dns.NODATA</code>: DNS server returned answer with no data.</li>
1571<li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li>
1572<li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li>
1573<li><code>dns.NOTFOUND</code>: Domain name not found.</li>
1574<li><code>dns.NOTIMP</code>: DNS server does not implement requested operation.</li>
1575<li><code>dns.REFUSED</code>: DNS server refused query.</li>
1576<li><code>dns.BADQUERY</code>: Misformatted DNS query.</li>
1577<li><code>dns.BADNAME</code>: Misformatted host name.</li>
1578<li><code>dns.BADFAMILY</code>: Unsupported address family.</li>
1579<li><code>dns.BADRESP</code>: Misformatted DNS reply.</li>
1580<li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li>
1581<li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li>
1582<li><code>dns.EOF</code>: End of file.</li>
1583<li><code>dns.FILE</code>: Error reading file.</li>
1584<li><code>dns.NOMEM</code>: Out of memory.</li>
1585<li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li>
1586<li><code>dns.BADSTR</code>: Misformatted string.</li>
1587<li><code>dns.BADFLAGS</code>: Illegal flags specified.</li>
1588<li><code>dns.NONAME</code>: Given host name is not numeric.</li>
1589<li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li>
1590<li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li>
1591<li><code>dns.LOADIPHLPAPI</code>: Error loading <code>iphlpapi.dll</code>.</li>
1592<li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find <code>GetNetworkParams</code> function.</li>
1593<li><code>dns.CANCELLED</code>: DNS query cancelled.</li>
1594</ul>
1595</section><section><h3>Implementation considerations<span><a class="mark" href="#dns_implementation_considerations" id="dns_implementation_considerations">#</a></span></h3>
1596<p>Although <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> and the various <code>dns.resolve*()/dns.reverse()</code>
1597functions have the same goal of associating a network name with a network
1598address (or vice versa), their behavior is quite different. These differences
1599can have subtle but significant consequences on the behavior of Node.js
1600programs.</p>
1601<h4><code>dns.lookup()</code><span><a class="mark" href="#dns_dns_lookup" id="dns_dns_lookup">#</a></span></h4>
1602<p>Under the hood, <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> uses the same operating system facilities
1603as most other programs. For instance, <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> will almost always
1604resolve a given name the same way as the <code>ping</code> command. On most POSIX-like
1605operating systems, the behavior of the <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> function can be
1606modified 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>,
1607but changing these files will change the behavior of all other
1608programs running on the same operating system.</p>
1609<p>Though the call to <code>dns.lookup()</code> will be asynchronous from JavaScript's
1610perspective, 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
1611on libuv's threadpool. This can have surprising negative performance
1612implications for some applications, see the <a href="cli.html#cli_uv_threadpool_size_size"><code>UV_THREADPOOL_SIZE</code></a>
1613documentation for more information.</p>
1614<p>Various networking APIs will call <code>dns.lookup()</code> internally to resolve
1615host names. If that is an issue, consider resolving the host name to an address
1616using <code>dns.resolve()</code> and using the address instead of a host name. Also, some
1617networking 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>)
1618allow the default resolver, <code>dns.lookup()</code>, to be replaced.</p>
1619<h4><code>dns.resolve()</code>, <code>dns.resolve*()</code> and <code>dns.reverse()</code><span><a class="mark" href="#dns_dns_resolve_dns_resolve_and_dns_reverse" id="dns_dns_resolve_dns_resolve_and_dns_reverse">#</a></span></h4>
1620<p>These functions are implemented quite differently than <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>. They
1621do 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
1622network. This network communication is always done asynchronously, and does not
1623use libuv's threadpool.</p>
1624<p>As a result, these functions cannot have the same negative impact on other
1625processing that happens on libuv's threadpool that <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> can have.</p>
1626<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>
1627uses. For instance, <em>they do not use the configuration from <code>/etc/hosts</code></em>.</p></section>
1628        <!-- API END -->
1629      </div>
1630    </div>
1631  </div>
1632  <script>
1633    'use strict';
1634    {
1635      const kCustomPreference = 'customDarkTheme';
1636      const userSettings = sessionStorage.getItem(kCustomPreference);
1637      const themeToggleButton = document.getElementById('theme-toggle-btn');
1638      if (userSettings === null && window.matchMedia) {
1639        const mq = window.matchMedia('(prefers-color-scheme: dark)');
1640        if ('onchange' in mq) {
1641          function mqChangeListener(e) {
1642            document.body.classList.toggle('dark-mode', e.matches);
1643          }
1644          mq.addEventListener('change', mqChangeListener);
1645          if (themeToggleButton) {
1646            themeToggleButton.addEventListener('click', function() {
1647              mq.removeEventListener('change', mqChangeListener);
1648            }, { once: true });
1649          }
1650        }
1651        if (mq.matches) {
1652          document.body.classList.add('dark-mode');
1653        }
1654      } else if (userSettings === 'true') {
1655        document.body.classList.add('dark-mode');
1656      }
1657      if (themeToggleButton) {
1658        themeToggleButton.hidden = false;
1659        themeToggleButton.addEventListener('click', function() {
1660          sessionStorage.setItem(
1661            kCustomPreference,
1662            document.body.classList.toggle('dark-mode')
1663          );
1664        });
1665      }
1666    }
1667  </script>
1668</body>
1669</html>
1670