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.20.1"> 7 <title>DNS | Node.js v14.20.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.20.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>▼</span></a> 119 <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v18.x/api/dns.html">18.x</a></li> 120<li><a href="https://nodejs.org/docs/latest-v17.x/api/dns.html">17.x</a></li> 121<li><a href="https://nodejs.org/docs/latest-v16.x/api/dns.html">16.x <b>LTS</b></a></li> 122<li><a href="https://nodejs.org/docs/latest-v15.x/api/dns.html">15.x</a></li> 123<li><a href="https://nodejs.org/docs/latest-v14.x/api/dns.html">14.x <b>LTS</b></a></li> 124<li><a href="https://nodejs.org/docs/latest-v13.x/api/dns.html">13.x</a></li> 125<li><a href="https://nodejs.org/docs/latest-v12.x/api/dns.html">12.x <b>LTS</b></a></li> 126<li><a href="https://nodejs.org/docs/latest-v11.x/api/dns.html">11.x</a></li> 127<li><a href="https://nodejs.org/docs/latest-v10.x/api/dns.html">10.x</a></li> 128<li><a href="https://nodejs.org/docs/latest-v9.x/api/dns.html">9.x</a></li> 129<li><a href="https://nodejs.org/docs/latest-v8.x/api/dns.html">8.x</a></li> 130<li><a href="https://nodejs.org/docs/latest-v7.x/api/dns.html">7.x</a></li> 131<li><a href="https://nodejs.org/docs/latest-v6.x/api/dns.html">6.x</a></li> 132<li><a href="https://nodejs.org/docs/latest-v5.x/api/dns.html">5.x</a></li> 133<li><a href="https://nodejs.org/docs/latest-v4.x/api/dns.html">4.x</a></li> 134<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/dns.html">0.12.x</a></li> 135<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/dns.html">0.10.x</a></li></ol> 136 </li> 137 138 <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/dns.md">Edit on GitHub</a></li> 139 </ul> 140 </div> 141 <hr> 142 </header> 143 144 <details id="toc" open><summary>Table of contents</summary><ul> 145<li><span class="stability_2"><a href="#dns_dns">DNS</a></span> 146<ul> 147<li><a href="#dns_class_dns_resolver">Class: <code>dns.Resolver</code></a> 148<ul> 149<li><a href="#dns_resolver_options"><code>Resolver([options])</code></a></li> 150<li><a href="#dns_resolver_cancel"><code>resolver.cancel()</code></a></li> 151<li><a href="#dns_resolver_setlocaladdress_ipv4_ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</code></a></li> 152</ul> 153</li> 154<li><a href="#dns_dns_getservers"><code>dns.getServers()</code></a></li> 155<li><a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup(hostname[, options], callback)</code></a> 156<ul> 157<li><a href="#dns_supported_getaddrinfo_flags">Supported getaddrinfo flags</a></li> 158</ul> 159</li> 160<li><a href="#dns_dns_lookupservice_address_port_callback"><code>dns.lookupService(address, port, callback)</code></a></li> 161<li><a href="#dns_dns_resolve_hostname_rrtype_callback"><code>dns.resolve(hostname[, rrtype], callback)</code></a></li> 162<li><a href="#dns_dns_resolve4_hostname_options_callback"><code>dns.resolve4(hostname[, options], callback)</code></a></li> 163<li><a href="#dns_dns_resolve6_hostname_options_callback"><code>dns.resolve6(hostname[, options], callback)</code></a></li> 164<li><a href="#dns_dns_resolveany_hostname_callback"><code>dns.resolveAny(hostname, callback)</code></a></li> 165<li><a href="#dns_dns_resolvecname_hostname_callback"><code>dns.resolveCname(hostname, callback)</code></a></li> 166<li><a href="#dns_dns_resolvecaa_hostname_callback"><code>dns.resolveCaa(hostname, callback)</code></a></li> 167<li><a href="#dns_dns_resolvemx_hostname_callback"><code>dns.resolveMx(hostname, callback)</code></a></li> 168<li><a href="#dns_dns_resolvenaptr_hostname_callback"><code>dns.resolveNaptr(hostname, callback)</code></a></li> 169<li><a href="#dns_dns_resolvens_hostname_callback"><code>dns.resolveNs(hostname, callback)</code></a></li> 170<li><a href="#dns_dns_resolveptr_hostname_callback"><code>dns.resolvePtr(hostname, callback)</code></a></li> 171<li><a href="#dns_dns_resolvesoa_hostname_callback"><code>dns.resolveSoa(hostname, callback)</code></a></li> 172<li><a href="#dns_dns_resolvesrv_hostname_callback"><code>dns.resolveSrv(hostname, callback)</code></a></li> 173<li><a href="#dns_dns_resolvetxt_hostname_callback"><code>dns.resolveTxt(hostname, callback)</code></a></li> 174<li><a href="#dns_dns_reverse_ip_callback"><code>dns.reverse(ip, callback)</code></a></li> 175<li><a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder(order)</code></a></li> 176<li><a href="#dns_dns_setservers_servers"><code>dns.setServers(servers)</code></a></li> 177<li><a href="#dns_dns_promises_api">DNS promises API</a> 178<ul> 179<li><a href="#dns_class_dnspromises_resolver">Class: <code>dnsPromises.Resolver</code></a></li> 180<li><a href="#dns_resolver_cancel_1"><code>resolver.cancel()</code></a></li> 181<li><a href="#dns_dnspromises_getservers"><code>dnsPromises.getServers()</code></a></li> 182<li><a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup(hostname[, options])</code></a></li> 183<li><a href="#dns_dnspromises_lookupservice_address_port"><code>dnsPromises.lookupService(address, port)</code></a></li> 184<li><a href="#dns_dnspromises_resolve_hostname_rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</code></a></li> 185<li><a href="#dns_dnspromises_resolve4_hostname_options"><code>dnsPromises.resolve4(hostname[, options])</code></a></li> 186<li><a href="#dns_dnspromises_resolve6_hostname_options"><code>dnsPromises.resolve6(hostname[, options])</code></a></li> 187<li><a href="#dns_dnspromises_resolveany_hostname"><code>dnsPromises.resolveAny(hostname)</code></a></li> 188<li><a href="#dns_dnspromises_resolvecaa_hostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li> 189<li><a href="#dns_dnspromises_resolvecname_hostname"><code>dnsPromises.resolveCname(hostname)</code></a></li> 190<li><a href="#dns_dnspromises_resolvemx_hostname"><code>dnsPromises.resolveMx(hostname)</code></a></li> 191<li><a href="#dns_dnspromises_resolvenaptr_hostname"><code>dnsPromises.resolveNaptr(hostname)</code></a></li> 192<li><a href="#dns_dnspromises_resolvens_hostname"><code>dnsPromises.resolveNs(hostname)</code></a></li> 193<li><a href="#dns_dnspromises_resolveptr_hostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li> 194<li><a href="#dns_dnspromises_resolvesoa_hostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li> 195<li><a href="#dns_dnspromises_resolvesrv_hostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li> 196<li><a href="#dns_dnspromises_resolvetxt_hostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li> 197<li><a href="#dns_dnspromises_reverse_ip"><code>dnsPromises.reverse(ip)</code></a></li> 198<li><a href="#dns_dnspromises_setdefaultresultorder_order"><code>dnsPromises.setDefaultResultOrder(order)</code></a></li> 199<li><a href="#dns_dnspromises_setservers_servers"><code>dnsPromises.setServers(servers)</code></a></li> 200</ul> 201</li> 202<li><a href="#dns_error_codes">Error codes</a></li> 203<li><a href="#dns_implementation_considerations">Implementation considerations</a> 204<ul> 205<li><a href="#dns_dns_lookup"><code>dns.lookup()</code></a></li> 206<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> 207</ul> 208</li> 209</ul> 210</li> 211</ul></details> 212 213 <div id="apicontent"> 214 <h2>DNS<span><a class="mark" href="#dns_dns" id="dns_dns">#</a></span></h2> 215 216<p></p><div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p> 217<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v14.20.1/lib/dns.js">lib/dns.js</a></p> 218<p>The <code>dns</code> module enables name resolution. For example, use it to look up IP 219addresses of host names.</p> 220<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 221DNS protocol for lookups. <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> uses the operating system 222facilities to perform name resolution. It may not need to perform any network 223communication. To perform name resolution the way other applications on the same 224system do, use <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>.</p> 225<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>); 226 227dns.<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> { 228 <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); 229}); 230<span class="hljs-comment">// address: "93.184.216.34" family: IPv4</span></code></pre> 231<p>All other functions in the <code>dns</code> module connect to an actual DNS server to 232perform name resolution. They will always use the network to perform DNS 233queries. These functions do not use the same set of configuration files used by 234<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 235DNS queries, bypassing other name-resolution facilities.</p> 236<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>); 237 238dns.<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> { 239 <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">throw</span> err; 240 241 <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>); 242 243 addresses.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">a</span>) =></span> { 244 dns.<span class="hljs-title function_">reverse</span>(a, <span class="hljs-function">(<span class="hljs-params">err, hostnames</span>) =></span> { 245 <span class="hljs-keyword">if</span> (err) { 246 <span class="hljs-keyword">throw</span> err; 247 } 248 <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>); 249 }); 250 }); 251});</code></pre> 252<p>See the <a href="#dns_implementation_considerations">Implementation considerations section</a> for more information.</p> 253<section><h3>Class: <code>dns.Resolver</code><span><a class="mark" href="#dns_class_dns_resolver" id="dns_class_dns_resolver">#</a></span></h3> 254<div class="api_metadata"> 255<span>Added in: v8.3.0</span> 256</div> 257<p>An independent resolver for DNS requests.</p> 258<p>Creating a new resolver uses the default server settings. Setting 259the servers used for a resolver using 260<a href="#dns_dns_setservers_servers"><code>resolver.setServers()</code></a> does not affect 261other resolvers:</p> 262<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>); 263<span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Resolver</span>(); 264resolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'</span>]); 265 266<span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global settings.</span> 267resolver.<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> { 268 <span class="hljs-comment">// ...</span> 269});</code></pre> 270<p>The following methods from the <code>dns</code> module are available:</p> 271<ul> 272<li><a href="#dns_dns_getservers"><code>resolver.getServers()</code></a></li> 273<li><a href="#dns_dns_resolve_hostname_rrtype_callback"><code>resolver.resolve()</code></a></li> 274<li><a href="#dns_dns_resolve4_hostname_options_callback"><code>resolver.resolve4()</code></a></li> 275<li><a href="#dns_dns_resolve6_hostname_options_callback"><code>resolver.resolve6()</code></a></li> 276<li><a href="#dns_dns_resolveany_hostname_callback"><code>resolver.resolveAny()</code></a></li> 277<li><a href="#dns_dns_resolvecaa_hostname_callback"><code>resolver.resolveCaa()</code></a></li> 278<li><a href="#dns_dns_resolvecname_hostname_callback"><code>resolver.resolveCname()</code></a></li> 279<li><a href="#dns_dns_resolvemx_hostname_callback"><code>resolver.resolveMx()</code></a></li> 280<li><a href="#dns_dns_resolvenaptr_hostname_callback"><code>resolver.resolveNaptr()</code></a></li> 281<li><a href="#dns_dns_resolvens_hostname_callback"><code>resolver.resolveNs()</code></a></li> 282<li><a href="#dns_dns_resolveptr_hostname_callback"><code>resolver.resolvePtr()</code></a></li> 283<li><a href="#dns_dns_resolvesoa_hostname_callback"><code>resolver.resolveSoa()</code></a></li> 284<li><a href="#dns_dns_resolvesrv_hostname_callback"><code>resolver.resolveSrv()</code></a></li> 285<li><a href="#dns_dns_resolvetxt_hostname_callback"><code>resolver.resolveTxt()</code></a></li> 286<li><a href="#dns_dns_reverse_ip_callback"><code>resolver.reverse()</code></a></li> 287<li><a href="#dns_dns_setservers_servers"><code>resolver.setServers()</code></a></li> 288</ul> 289<h4><code>Resolver([options])</code><span><a class="mark" href="#dns_resolver_options" id="dns_resolver_options">#</a></span></h4> 290<div class="api_metadata"> 291<details class="changelog"><summary>History</summary> 292<table> 293<tbody><tr><th>Version</th><th>Changes</th></tr> 294<tr><td>v14.18.0</td> 295<td><p>The <code>options</code> object now accepts a <code>tries</code> option.</p></td></tr> 296<tr><td>v14.5.0</td> 297<td><p>The constructor now accepts an <code>options</code> object. The single supported option is <code>timeout</code>.</p></td></tr> 298<tr><td>v8.3.0</td> 299<td><p><span>Added in: v8.3.0</span></p></td></tr> 300</tbody></table> 301</details> 302</div> 303<p>Create a new resolver.</p> 304<ul> 305<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 306<ul> 307<li><code>timeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> Query timeout in milliseconds, or <code>-1</code> to use the 308default timeout.</li> 309<li><code>tries</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> The number of tries the resolver will try contacting 310each name server before giving up. <strong>Default:</strong> <code>4</code></li> 311</ul> 312</li> 313</ul> 314<h4><code>resolver.cancel()</code><span><a class="mark" href="#dns_resolver_cancel" id="dns_resolver_cancel">#</a></span></h4> 315<div class="api_metadata"> 316<span>Added in: v8.3.0</span> 317</div> 318<p>Cancel all outstanding DNS queries made by this resolver. The corresponding 319callbacks will be called with an error with code <code>ECANCELLED</code>.</p> 320<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> 321<div class="api_metadata"> 322<span>Added in: v14.17.0</span> 323</div> 324<ul> 325<li><code>ipv4</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A string representation of an IPv4 address. 326<strong>Default:</strong> <code>'0.0.0.0'</code></li> 327<li><code>ipv6</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A string representation of an IPv6 address. 328<strong>Default:</strong> <code>'::0'</code></li> 329</ul> 330<p>The resolver instance will send its requests from the specified IP address. 331This allows programs to specify outbound interfaces when used on multi-homed 332systems.</p> 333<p>If a v4 or v6 address is not specified, it is set to the default, and the 334operating system will choose a local address automatically.</p> 335<p>The resolver will use the v4 local address when making requests to IPv4 DNS 336servers, and the v6 local address when making requests to IPv6 DNS servers. 337The <code>rrtype</code> of resolution requests has no impact on the local address used.</p> 338</section><section><h3><code>dns.getServers()</code><span><a class="mark" href="#dns_dns_getservers" id="dns_dns_getservers">#</a></span></h3> 339<div class="api_metadata"> 340<span>Added in: v0.11.3</span> 341</div> 342<ul> 343<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 344</ul> 345<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>, 346that are currently configured for DNS resolution. A string will include a port 347section if a custom port is used.</p> 348<!-- eslint-disable semi--> 349<pre><code class="language-js">[ 350 <span class="hljs-string">'4.4.4.4'</span>, 351 <span class="hljs-string">'2001:4860:4860::8888'</span>, 352 <span class="hljs-string">'4.4.4.4:1053'</span>, 353 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>, 354]</code></pre> 355</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> 356<div class="api_metadata"> 357<details class="changelog"><summary>History</summary> 358<table> 359<tbody><tr><th>Version</th><th>Changes</th></tr> 360<tr><td>v8.5.0</td> 361<td><p>The <code>verbatim</code> option is supported now.</p></td></tr> 362<tr><td>v1.2.0</td> 363<td><p>The <code>all</code> option is supported now.</p></td></tr> 364<tr><td>v0.1.90</td> 365<td><p><span>Added in: v0.1.90</span></p></td></tr> 366</tbody></table> 367</details> 368</div> 369<ul> 370<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 371<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 372<ul> 373<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. The value 374<code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong> 375<code>0</code>.</li> 376<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> One or more <a href="#dns_supported_getaddrinfo_flags">supported <code>getaddrinfo</code> flags</a>. Multiple 377flags may be passed by bitwise <code>OR</code>ing their values.</li> 378<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> When <code>true</code>, the callback returns all resolved addresses in 379an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li> 380<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> When <code>true</code>, the callback receives IPv4 and IPv6 381addresses in the order the DNS resolver returned them. When <code>false</code>, 382IPv4 addresses are placed before IPv6 addresses. 383<strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is 384expected to change in the not too distant future. Default value is 385configurable using <a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> or 386<a href="cli.html#cli_dns_result_order_order"><code>--dns-result-order</code></a>. New code should use <code>{ verbatim: true }</code>.</li> 387</ul> 388</li> 389<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 390<ul> 391<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 392<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A string representation of an IPv4 or IPv6 address.</li> 393<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> <code>4</code> or <code>6</code>, denoting the family of <code>address</code>, or <code>0</code> if 394the address is not an IPv4 or IPv6 address. <code>0</code> is a likely indicator of a 395bug in the name resolution service used by the operating system.</li> 396</ul> 397</li> 398</ul> 399<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or 400AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an 401integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided, then IPv4 402and IPv6 addresses are both returned if found.</p> 403<p>With the <code>all</code> option set to <code>true</code>, the arguments for <code>callback</code> change to 404<code>(err, addresses)</code>, with <code>addresses</code> being an array of objects with the 405properties <code>address</code> and <code>family</code>.</p> 406<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. 407Keep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when 408the host name does not exist but also when the lookup fails in other ways 409such as no available file descriptors.</p> 410<p><code>dns.lookup()</code> does not necessarily have anything to do with the DNS protocol. 411The implementation uses an operating system facility that can associate names 412with addresses, and vice versa. This implementation can have subtle but 413important consequences on the behavior of any Node.js program. Please take some 414time to consult the <a href="#dns_implementation_considerations">Implementation considerations section</a> before using 415<code>dns.lookup()</code>.</p> 416<p>Example usage:</p> 417<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>); 418<span class="hljs-keyword">const</span> options = { 419 <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>, 420 <span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<span class="hljs-property">V4MAPPED</span>, 421}; 422dns.<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> 423 <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)); 424<span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span> 425 426<span class="hljs-comment">// When options.all is true, the result will be an Array.</span> 427options.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>; 428dns.<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> 429 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'addresses: %j'</span>, addresses)); 430<span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]</span></code></pre> 431<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> 432is not set to <code>true</code>, it returns a <code>Promise</code> for an <code>Object</code> with <code>address</code> and 433<code>family</code> properties.</p> 434<h4>Supported getaddrinfo flags<span><a class="mark" href="#dns_supported_getaddrinfo_flags" id="dns_supported_getaddrinfo_flags">#</a></span></h4> 435<div class="api_metadata"> 436<details class="changelog"><summary>History</summary> 437<table> 438<tbody><tr><th>Version</th><th>Changes</th></tr> 439<tr><td>v14.0.0</td> 440<td><p>Added support for the <code>dns.ALL</code> flag.</p></td></tr> 441</tbody></table> 442</details> 443</div> 444<p>The following flags can be passed as hints to <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>.</p> 445<ul> 446<li><code>dns.ADDRCONFIG</code>: Limits returned address types to the types of non-loopback 447addresses configured on the system. For example, IPv4 addresses are only 448returned if the current system has at least one IPv4 address configured.</li> 449<li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses were 450found, then return IPv4 mapped IPv6 addresses. It is not supported 451on some operating systems (e.g FreeBSD 10.1).</li> 452<li><code>dns.ALL</code>: If <code>dns.V4MAPPED</code> is specified, return resolved IPv6 addresses as 453well as IPv4 mapped IPv6 addresses.</li> 454</ul> 455</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> 456<div class="api_metadata"> 457<span>Added in: v0.11.14</span> 458</div> 459<ul> 460<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 461<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 462<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 463<ul> 464<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 465<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> e.g. <code>example.com</code></li> 466<li><code>service</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> e.g. <code>http</code></li> 467</ul> 468</li> 469</ul> 470<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using 471the operating system's underlying <code>getnameinfo</code> implementation.</p> 472<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown. 473The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code> 474will be thrown.</p> 475<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> 476<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>); 477dns.<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> { 478 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(hostname, service); 479 <span class="hljs-comment">// Prints: localhost ssh</span> 480});</code></pre> 481<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 482<code>Promise</code> for an <code>Object</code> with <code>hostname</code> and <code>service</code> properties.</p> 483</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> 484<div class="api_metadata"> 485<span>Added in: v0.1.27</span> 486</div> 487<ul> 488<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Host name to resolve.</li> 489<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Resource record type. <strong>Default:</strong> <code>'A'</code>.</li> 490<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 491<ul> 492<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 493<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> 494</ul> 495</li> 496</ul> 497<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array 498of the resource records. The <code>callback</code> function has arguments 499<code>(err, records)</code>. When successful, <code>records</code> will be an array of resource 500records. The type and structure of individual results varies based on <code>rrtype</code>:</p> 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 584<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"><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"><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"><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"><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"><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"><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"><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"><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"><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"><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"><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"><string[]></a></td><td><a href="#dns_dns_resolvetxt_hostname_callback"><code>dns.resolveTxt()</code></a></td></tr></tbody></table> 585<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 586<a href="#dns_error_codes">DNS error codes</a>.</p> 587</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> 588<div class="api_metadata"> 589<details class="changelog"><summary>History</summary> 590<table> 591<tbody><tr><th>Version</th><th>Changes</th></tr> 592<tr><td>v7.2.0</td> 593<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p></td></tr> 594<tr><td>v0.1.16</td> 595<td><p><span>Added in: v0.1.16</span></p></td></tr> 596</tbody></table> 597</details> 598</div> 599<ul> 600<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Host name to resolve.</li> 601<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 602<ul> 603<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> Retrieve the Time-To-Live value (TTL) of each record. 604When <code>true</code>, the callback receives an array of 605<code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings, 606with the TTL expressed in seconds.</li> 607</ul> 608</li> 609<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 610<ul> 611<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 612<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 613</ul> 614</li> 615</ul> 616<p>Uses the DNS protocol to resolve a IPv4 addresses (<code>A</code> records) for the 617<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function 618will contain an array of IPv4 addresses (e.g. 619<code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p> 620</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> 621<div class="api_metadata"> 622<details class="changelog"><summary>History</summary> 623<table> 624<tbody><tr><th>Version</th><th>Changes</th></tr> 625<tr><td>v7.2.0</td> 626<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p></td></tr> 627<tr><td>v0.1.16</td> 628<td><p><span>Added in: v0.1.16</span></p></td></tr> 629</tbody></table> 630</details> 631</div> 632<ul> 633<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Host name to resolve.</li> 634<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 635<ul> 636<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> Retrieve the Time-To-Live value (TTL) of each record. 637When <code>true</code>, the callback receives an array of 638<code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of 639strings, with the TTL expressed in seconds.</li> 640</ul> 641</li> 642<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 643<ul> 644<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 645<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 646</ul> 647</li> 648</ul> 649<p>Uses the DNS protocol to resolve a IPv6 addresses (<code>AAAA</code> records) for the 650<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function 651will contain an array of IPv6 addresses.</p> 652</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> 653<ul> 654<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 655<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 656<ul> 657<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 658<li><code>ret</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 659</ul> 660</li> 661</ul> 662<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query). 663The <code>ret</code> argument passed to the <code>callback</code> function will be an array containing 664various types of records. Each object has a property <code>type</code> that indicates the 665type of the current record. And depending on the <code>type</code>, additional properties 666will be present on the object:</p> 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 716<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> 717<p>Here is an example of the <code>ret</code> object passed to the callback:</p> 718<!-- eslint-disable semi --> 719<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> }, 720 { <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> }, 721 { <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> }, 722 { <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> }, 723 { <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> ] }, 724 { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>, 725 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>, 726 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>, 727 <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>, 728 <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>, 729 <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>, 730 <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>, 731 <span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code></pre> 732<p>DNS server operators may choose not to respond to <code>ANY</code> 733queries. It may be better to call individual methods like <a href="#dns_dns_resolve4_hostname_options_callback"><code>dns.resolve4()</code></a>, 734<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> 735</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> 736<div class="api_metadata"> 737<span>Added in: v0.3.2</span> 738</div> 739<ul> 740<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 741<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 742<ul> 743<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 744<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 745</ul> 746</li> 747</ul> 748<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. The 749<code>addresses</code> argument passed to the <code>callback</code> function 750will contain an array of canonical name records available for the <code>hostname</code> 751(e.g. <code>['bar.example.com']</code>).</p> 752</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> 753<div class="api_metadata"> 754<span>Added in: v14.17.0</span> 755</div> 756<ul> 757<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 758<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 759<ul> 760<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 761<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 762</ul> 763</li> 764</ul> 765<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. The 766<code>addresses</code> argument passed to the <code>callback</code> function 767will contain an array of certification authority authorization records 768available for the <code>hostname</code> (e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]</code>).</p> 769</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> 770<div class="api_metadata"> 771<span>Added in: v0.1.27</span> 772</div> 773<ul> 774<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 775<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 776<ul> 777<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 778<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 779</ul> 780</li> 781</ul> 782<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the 783<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will 784contain an array of objects containing both a <code>priority</code> and <code>exchange</code> 785property (e.g. <code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p> 786</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> 787<div class="api_metadata"> 788<span>Added in: v0.9.12</span> 789</div> 790<ul> 791<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 792<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 793<ul> 794<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 795<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 796</ul> 797</li> 798</ul> 799<p>Uses the DNS protocol to resolve regular expression based records (<code>NAPTR</code> 800records) for the <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> 801function will contain an array of objects with the following properties:</p> 802<ul> 803<li><code>flags</code></li> 804<li><code>service</code></li> 805<li><code>regexp</code></li> 806<li><code>replacement</code></li> 807<li><code>order</code></li> 808<li><code>preference</code></li> 809</ul> 810<!-- eslint-skip --> 811<pre><code class="language-js">{ 812 <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>, 813 <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>, 814 <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>, 815 <span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</span>, 816 <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>, 817 <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span> 818}</code></pre> 819</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> 820<div class="api_metadata"> 821<span>Added in: v0.1.90</span> 822</div> 823<ul> 824<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 825<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 826<ul> 827<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 828<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 829</ul> 830</li> 831</ul> 832<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the 833<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will 834contain an array of name server records available for <code>hostname</code> 835(e.g. <code>['ns1.example.com', 'ns2.example.com']</code>).</p> 836</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> 837<div class="api_metadata"> 838<span>Added in: v6.0.0</span> 839</div> 840<ul> 841<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 842<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 843<ul> 844<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 845<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 846</ul> 847</li> 848</ul> 849<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the 850<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will 851be an array of strings containing the reply records.</p> 852</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> 853<div class="api_metadata"> 854<span>Added in: v0.11.10</span> 855</div> 856<ul> 857<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 858<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 859<ul> 860<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 861<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> 862</ul> 863</li> 864</ul> 865<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for 866the <code>hostname</code>. The <code>address</code> argument passed to the <code>callback</code> function will 867be an object with the following properties:</p> 868<ul> 869<li><code>nsname</code></li> 870<li><code>hostmaster</code></li> 871<li><code>serial</code></li> 872<li><code>refresh</code></li> 873<li><code>retry</code></li> 874<li><code>expire</code></li> 875<li><code>minttl</code></li> 876</ul> 877<!-- eslint-skip --> 878<pre><code class="language-js">{ 879 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>, 880 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>, 881 <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>, 882 <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>, 883 <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>, 884 <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>, 885 <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span> 886}</code></pre> 887</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> 888<div class="api_metadata"> 889<span>Added in: v0.1.27</span> 890</div> 891<ul> 892<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 893<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 894<ul> 895<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 896<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object[]></a></li> 897</ul> 898</li> 899</ul> 900<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the 901<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will 902be an array of objects with the following properties:</p> 903<ul> 904<li><code>priority</code></li> 905<li><code>weight</code></li> 906<li><code>port</code></li> 907<li><code>name</code></li> 908</ul> 909<!-- eslint-skip --> 910<pre><code class="language-js">{ 911 <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>, 912 <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>, 913 <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>, 914 <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span> 915}</code></pre> 916</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> 917<div class="api_metadata"> 918<span>Added in: v0.1.27</span> 919</div> 920<!--lint disable no-undefined-references list-item-bullet-indent--> 921<ul> 922<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 923<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 924<ul> 925<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 926<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[][]></a></li> 927</ul> 928</li> 929</ul> 930<!--lint enable no-undefined-references list-item-bullet-indent--> 931<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the 932<code>hostname</code>. The <code>records</code> argument passed to the <code>callback</code> function is a 933two-dimensional array of the text records available for <code>hostname</code> (e.g. 934<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of 935one record. Depending on the use case, these could be either joined together or 936treated separately.</p> 937</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> 938<div class="api_metadata"> 939<span>Added in: v0.1.16</span> 940</div> 941<ul> 942<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 943<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 944<ul> 945<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a></li> 946<li><code>hostnames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 947</ul> 948</li> 949</ul> 950<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an 951array of host names.</p> 952<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 953one of the <a href="#dns_error_codes">DNS error codes</a>.</p> 954</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> 955<div class="api_metadata"> 956<span>Added in: v14.18.0</span> 957</div> 958<ul> 959<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> must be <code>'ipv4first'</code> or <code>'verbatim'</code>.</li> 960</ul> 961<p>Set the default value of <code>verbatim</code> in <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> and 962<a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup()</code></a>. The value could be:</p> 963<ul> 964<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li> 965<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li> 966</ul> 967<p>The default is <code>ipv4first</code> and <a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> have higher 968priority 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>, 969<a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> from the main thread won't affect the default 970dns orders in workers.</p> 971</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> 972<div class="api_metadata"> 973<span>Added in: v0.11.3</span> 974</div> 975<ul> 976<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li> 977</ul> 978<p>Sets the IP address and port of servers to be used when performing DNS 979resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted 980addresses. If the port is the IANA default DNS port (53) it can be omitted.</p> 981<pre><code class="language-js">dns.<span class="hljs-title function_">setServers</span>([ 982 <span class="hljs-string">'4.4.4.4'</span>, 983 <span class="hljs-string">'[2001:4860:4860::8888]'</span>, 984 <span class="hljs-string">'4.4.4.4:1053'</span>, 985 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>, 986]);</code></pre> 987<p>An error will be thrown if an invalid address is provided.</p> 988<p>The <code>dns.setServers()</code> method must not be called while a DNS query is in 989progress.</p> 990<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>, 991<code>dns.resolve*()</code> and <a href="#dns_dns_reverse_ip_callback"><code>dns.reverse()</code></a> (and specifically <em>not</em> 992<a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>).</p> 993<p>This method works much like 994<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>. 995That is, if attempting to resolve with the first server provided results in a 996<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with 997subsequent servers provided. Fallback DNS servers will only be used if the 998earlier ones time out or result in some other error.</p> 999</section><section><h3>DNS promises API<span><a class="mark" href="#dns_dns_promises_api" id="dns_dns_promises_api">#</a></span></h3> 1000<div class="api_metadata"> 1001<details class="changelog"><summary>History</summary> 1002<table> 1003<tbody><tr><th>Version</th><th>Changes</th></tr> 1004<tr><td>v11.14.0, v10.17.0</td> 1005<td><p>This API is no longer experimental.</p></td></tr> 1006<tr><td>v10.6.0</td> 1007<td><p><span>Added in: v10.6.0</span></p></td></tr> 1008</tbody></table> 1009</details> 1010</div> 1011<p>The <code>dns.promises</code> API provides an alternative set of asynchronous DNS methods 1012that return <code>Promise</code> objects rather than using callbacks. The API is accessible 1013via <code>require('dns').promises</code>.</p> 1014<h4>Class: <code>dnsPromises.Resolver</code><span><a class="mark" href="#dns_class_dnspromises_resolver" id="dns_class_dnspromises_resolver">#</a></span></h4> 1015<div class="api_metadata"> 1016<span>Added in: v10.6.0</span> 1017</div> 1018<p>An independent resolver for DNS requests.</p> 1019<p>Creating a new resolver uses the default server settings. Setting 1020the servers used for a resolver using 1021<a href="#dns_dnspromises_setservers_servers"><code>resolver.setServers()</code></a> does not affect 1022other resolvers:</p> 1023<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>; 1024<span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Resolver</span>(); 1025resolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'</span>]); 1026 1027<span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global settings.</span> 1028resolver.<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> { 1029 <span class="hljs-comment">// ...</span> 1030}); 1031 1032<span class="hljs-comment">// Alternatively, the same code can be written using async-await style.</span> 1033(<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) { 1034 <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>); 1035})();</code></pre> 1036<p>The following methods from the <code>dnsPromises</code> API are available:</p> 1037<ul> 1038<li><a href="#dns_dnspromises_getservers"><code>resolver.getServers()</code></a></li> 1039<li><a href="#dns_dnspromises_resolve_hostname_rrtype"><code>resolver.resolve()</code></a></li> 1040<li><a href="#dns_dnspromises_resolve4_hostname_options"><code>resolver.resolve4()</code></a></li> 1041<li><a href="#dns_dnspromises_resolve6_hostname_options"><code>resolver.resolve6()</code></a></li> 1042<li><a href="#dns_dnspromises_resolveany_hostname"><code>resolver.resolveAny()</code></a></li> 1043<li><a href="#dns_dnspromises_resolvecaa_hostname"><code>resolver.resolveCaa()</code></a></li> 1044<li><a href="#dns_dnspromises_resolvecname_hostname"><code>resolver.resolveCname()</code></a></li> 1045<li><a href="#dns_dnspromises_resolvemx_hostname"><code>resolver.resolveMx()</code></a></li> 1046<li><a href="#dns_dnspromises_resolvenaptr_hostname"><code>resolver.resolveNaptr()</code></a></li> 1047<li><a href="#dns_dnspromises_resolvens_hostname"><code>resolver.resolveNs()</code></a></li> 1048<li><a href="#dns_dnspromises_resolveptr_hostname"><code>resolver.resolvePtr()</code></a></li> 1049<li><a href="#dns_dnspromises_resolvesoa_hostname"><code>resolver.resolveSoa()</code></a></li> 1050<li><a href="#dns_dnspromises_resolvesrv_hostname"><code>resolver.resolveSrv()</code></a></li> 1051<li><a href="#dns_dnspromises_resolvetxt_hostname"><code>resolver.resolveTxt()</code></a></li> 1052<li><a href="#dns_dnspromises_reverse_ip"><code>resolver.reverse()</code></a></li> 1053<li><a href="#dns_dnspromises_setservers_servers"><code>resolver.setServers()</code></a></li> 1054</ul> 1055<h4><code>resolver.cancel()</code><span><a class="mark" href="#dns_resolver_cancel_1" id="dns_resolver_cancel_1">#</a></span></h4> 1056<div class="api_metadata"> 1057<span>Added in: v14.17.0</span> 1058</div> 1059<p>Cancel all outstanding DNS queries made by this resolver. The corresponding 1060promises will be rejected with an error with code <code>ECANCELLED</code>.</p> 1061<h4><code>dnsPromises.getServers()</code><span><a class="mark" href="#dns_dnspromises_getservers" id="dns_dnspromises_getservers">#</a></span></h4> 1062<div class="api_metadata"> 1063<span>Added in: v10.6.0</span> 1064</div> 1065<ul> 1066<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 1067</ul> 1068<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>, 1069that are currently configured for DNS resolution. A string will include a port 1070section if a custom port is used.</p> 1071<!-- eslint-disable semi--> 1072<pre><code class="language-js">[ 1073 <span class="hljs-string">'4.4.4.4'</span>, 1074 <span class="hljs-string">'2001:4860:4860::8888'</span>, 1075 <span class="hljs-string">'4.4.4.4:1053'</span>, 1076 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>, 1077]</code></pre> 1078<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> 1079<div class="api_metadata"> 1080<span>Added in: v10.6.0</span> 1081</div> 1082<ul> 1083<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1084<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 1085<ul> 1086<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. The value 1087<code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong> 1088<code>0</code>.</li> 1089<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> One or more <a href="#dns_supported_getaddrinfo_flags">supported <code>getaddrinfo</code> flags</a>. Multiple 1090flags may be passed by bitwise <code>OR</code>ing their values.</li> 1091<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> When <code>true</code>, the <code>Promise</code> is resolved with all addresses in 1092an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li> 1093<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> When <code>true</code>, the <code>Promise</code> is resolved with IPv4 and 1094IPv6 addresses in the order the DNS resolver returned them. When <code>false</code>, 1095IPv4 addresses are placed before IPv6 addresses. 1096<strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is 1097expected to change in the not too distant future. Default value is 1098configurable using <a href="#dns_dns_setdefaultresultorder_order"><code>dns.setDefaultResultOrder()</code></a> or 1099<a href="cli.html#cli_dns_result_order_order"><code>--dns-result-order</code></a>. New code should use <code>{ verbatim: true }</code>.</li> 1100</ul> 1101</li> 1102</ul> 1103<p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or 1104AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an 1105integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided, then IPv4 1106and IPv6 addresses are both returned if found.</p> 1107<p>With the <code>all</code> option set to <code>true</code>, the <code>Promise</code> is resolved with <code>addresses</code> 1108being an array of objects with the properties <code>address</code> and <code>family</code>.</p> 1109<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> 1110is the error code. 1111Keep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when 1112the host name does not exist but also when the lookup fails in other ways 1113such as no available file descriptors.</p> 1114<p><a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup()</code></a> does not necessarily have anything to do with the DNS 1115protocol. The implementation uses an operating system facility that can 1116associate names with addresses, and vice versa. This implementation can have 1117subtle but important consequences on the behavior of any Node.js program. Please 1118take some time to consult the <a href="#dns_implementation_considerations">Implementation considerations section</a> before 1119using <code>dnsPromises.lookup()</code>.</p> 1120<p>Example usage:</p> 1121<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>); 1122<span class="hljs-keyword">const</span> dnsPromises = dns.<span class="hljs-property">promises</span>; 1123<span class="hljs-keyword">const</span> options = { 1124 <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>, 1125 <span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<span class="hljs-property">V4MAPPED</span>, 1126}; 1127 1128dnsPromises.<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> { 1129 <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>); 1130 <span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span> 1131}); 1132 1133<span class="hljs-comment">// When options.all is true, the result will be an Array.</span> 1134options.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>; 1135dnsPromises.<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> { 1136 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'addresses: %j'</span>, result); 1137 <span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]</span> 1138});</code></pre> 1139<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> 1140<div class="api_metadata"> 1141<span>Added in: v10.6.0</span> 1142</div> 1143<ul> 1144<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1145<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1146</ul> 1147<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using 1148the operating system's underlying <code>getnameinfo</code> implementation.</p> 1149<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown. 1150The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code> 1151will be thrown.</p> 1152<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> 1153is the error code.</p> 1154<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>; 1155dnsPromises.<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> { 1156 <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>); 1157 <span class="hljs-comment">// Prints: localhost ssh</span> 1158});</code></pre> 1159<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> 1160<div class="api_metadata"> 1161<span>Added in: v10.6.0</span> 1162</div> 1163<ul> 1164<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Host name to resolve.</li> 1165<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Resource record type. <strong>Default:</strong> <code>'A'</code>.</li> 1166</ul> 1167<p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array 1168of the resource records. When successful, the <code>Promise</code> is resolved with an 1169array of resource records. The type and structure of individual results vary 1170based on <code>rrtype</code>:</p> 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 1254<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"><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"><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"><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"><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"><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"><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"><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"><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"><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"><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"><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"><string[]></a></td><td><a href="#dns_dnspromises_resolvetxt_hostname"><code>dnsPromises.resolveTxt()</code></a></td></tr></tbody></table> 1255<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> 1256is one of the <a href="#dns_error_codes">DNS error codes</a>.</p> 1257<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> 1258<div class="api_metadata"> 1259<span>Added in: v10.6.0</span> 1260</div> 1261<ul> 1262<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Host name to resolve.</li> 1263<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 1264<ul> 1265<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> Retrieve the Time-To-Live value (TTL) of each record. 1266When <code>true</code>, the <code>Promise</code> is resolved with an array of 1267<code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings, 1268with the TTL expressed in seconds.</li> 1269</ul> 1270</li> 1271</ul> 1272<p>Uses the DNS protocol to resolve IPv4 addresses (<code>A</code> records) for the 1273<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv4 1274addresses (e.g. <code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p> 1275<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> 1276<div class="api_metadata"> 1277<span>Added in: v10.6.0</span> 1278</div> 1279<ul> 1280<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Host name to resolve.</li> 1281<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 1282<ul> 1283<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> Retrieve the Time-To-Live value (TTL) of each record. 1284When <code>true</code>, the <code>Promise</code> is resolved with an array of 1285<code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of 1286strings, with the TTL expressed in seconds.</li> 1287</ul> 1288</li> 1289</ul> 1290<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the 1291<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv6 1292addresses.</p> 1293<h4><code>dnsPromises.resolveAny(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolveany_hostname" id="dns_dnspromises_resolveany_hostname">#</a></span></h4> 1294<div class="api_metadata"> 1295<span>Added in: v10.6.0</span> 1296</div> 1297<ul> 1298<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1299</ul> 1300<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query). 1301On success, the <code>Promise</code> is resolved with an array containing various types of 1302records. Each object has a property <code>type</code> that indicates the type of the 1303current record. And depending on the <code>type</code>, additional properties will be 1304present on the object:</p> 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 1354<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> 1355<p>Here is an example of the result object:</p> 1356<!-- eslint-disable semi --> 1357<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> }, 1358 { <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> }, 1359 { <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> }, 1360 { <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> }, 1361 { <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> ] }, 1362 { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>, 1363 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>, 1364 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>, 1365 <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>, 1366 <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>, 1367 <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>, 1368 <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>, 1369 <span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code></pre> 1370<h4><code>dnsPromises.resolveCaa(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvecaa_hostname" id="dns_dnspromises_resolvecaa_hostname">#</a></span></h4> 1371<div class="api_metadata"> 1372<span>Added in: v14.17.0</span> 1373</div> 1374<ul> 1375<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1376</ul> 1377<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. On success, 1378the <code>Promise</code> is resolved with an array of objects containing available 1379certification authority authorization records available for the <code>hostname</code> 1380(e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]</code>).</p> 1381<h4><code>dnsPromises.resolveCname(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvecname_hostname" id="dns_dnspromises_resolvecname_hostname">#</a></span></h4> 1382<div class="api_metadata"> 1383<span>Added in: v10.6.0</span> 1384</div> 1385<ul> 1386<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1387</ul> 1388<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. On success, 1389the <code>Promise</code> is resolved with an array of canonical name records available for 1390the <code>hostname</code> (e.g. <code>['bar.example.com']</code>).</p> 1391<h4><code>dnsPromises.resolveMx(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvemx_hostname" id="dns_dnspromises_resolvemx_hostname">#</a></span></h4> 1392<div class="api_metadata"> 1393<span>Added in: v10.6.0</span> 1394</div> 1395<ul> 1396<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1397</ul> 1398<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the 1399<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects 1400containing both a <code>priority</code> and <code>exchange</code> property (e.g. 1401<code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p> 1402<h4><code>dnsPromises.resolveNaptr(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvenaptr_hostname" id="dns_dnspromises_resolvenaptr_hostname">#</a></span></h4> 1403<div class="api_metadata"> 1404<span>Added in: v10.6.0</span> 1405</div> 1406<ul> 1407<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1408</ul> 1409<p>Uses the DNS protocol to resolve regular expression based records (<code>NAPTR</code> 1410records) for the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array 1411of objects with the following properties:</p> 1412<ul> 1413<li><code>flags</code></li> 1414<li><code>service</code></li> 1415<li><code>regexp</code></li> 1416<li><code>replacement</code></li> 1417<li><code>order</code></li> 1418<li><code>preference</code></li> 1419</ul> 1420<!-- eslint-skip --> 1421<pre><code class="language-js">{ 1422 <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>, 1423 <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>, 1424 <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>, 1425 <span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</span>, 1426 <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>, 1427 <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span> 1428}</code></pre> 1429<h4><code>dnsPromises.resolveNs(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvens_hostname" id="dns_dnspromises_resolvens_hostname">#</a></span></h4> 1430<div class="api_metadata"> 1431<span>Added in: v10.6.0</span> 1432</div> 1433<ul> 1434<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1435</ul> 1436<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the 1437<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of name server 1438records available for <code>hostname</code> (e.g. 1439<code>['ns1.example.com', 'ns2.example.com']</code>).</p> 1440<h4><code>dnsPromises.resolvePtr(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolveptr_hostname" id="dns_dnspromises_resolveptr_hostname">#</a></span></h4> 1441<div class="api_metadata"> 1442<span>Added in: v10.6.0</span> 1443</div> 1444<ul> 1445<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1446</ul> 1447<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the 1448<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of strings 1449containing the reply records.</p> 1450<h4><code>dnsPromises.resolveSoa(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvesoa_hostname" id="dns_dnspromises_resolvesoa_hostname">#</a></span></h4> 1451<div class="api_metadata"> 1452<span>Added in: v10.6.0</span> 1453</div> 1454<ul> 1455<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1456</ul> 1457<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for 1458the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an object with the 1459following properties:</p> 1460<ul> 1461<li><code>nsname</code></li> 1462<li><code>hostmaster</code></li> 1463<li><code>serial</code></li> 1464<li><code>refresh</code></li> 1465<li><code>retry</code></li> 1466<li><code>expire</code></li> 1467<li><code>minttl</code></li> 1468</ul> 1469<!-- eslint-skip --> 1470<pre><code class="language-js">{ 1471 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>, 1472 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>, 1473 <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>, 1474 <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>, 1475 <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>, 1476 <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>, 1477 <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span> 1478}</code></pre> 1479<h4><code>dnsPromises.resolveSrv(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvesrv_hostname" id="dns_dnspromises_resolvesrv_hostname">#</a></span></h4> 1480<div class="api_metadata"> 1481<span>Added in: v10.6.0</span> 1482</div> 1483<ul> 1484<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1485</ul> 1486<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the 1487<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects with 1488the following properties:</p> 1489<ul> 1490<li><code>priority</code></li> 1491<li><code>weight</code></li> 1492<li><code>port</code></li> 1493<li><code>name</code></li> 1494</ul> 1495<!-- eslint-skip --> 1496<pre><code class="language-js">{ 1497 <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>, 1498 <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>, 1499 <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>, 1500 <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span> 1501}</code></pre> 1502<h4><code>dnsPromises.resolveTxt(hostname)</code><span><a class="mark" href="#dns_dnspromises_resolvetxt_hostname" id="dns_dnspromises_resolvetxt_hostname">#</a></span></h4> 1503<div class="api_metadata"> 1504<span>Added in: v10.6.0</span> 1505</div> 1506<ul> 1507<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1508</ul> 1509<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the 1510<code>hostname</code>. On success, the <code>Promise</code> is resolved with a two-dimensional array 1511of the text records available for <code>hostname</code> (e.g. 1512<code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of 1513one record. Depending on the use case, these could be either joined together or 1514treated separately.</p> 1515<h4><code>dnsPromises.reverse(ip)</code><span><a class="mark" href="#dns_dnspromises_reverse_ip" id="dns_dnspromises_reverse_ip">#</a></span></h4> 1516<div class="api_metadata"> 1517<span>Added in: v10.6.0</span> 1518</div> 1519<ul> 1520<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1521</ul> 1522<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an 1523array of host names.</p> 1524<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> 1525is one of the <a href="#dns_error_codes">DNS error codes</a>.</p> 1526<h4><code>dnsPromises.setDefaultResultOrder(order)</code><span><a class="mark" href="#dns_dnspromises_setdefaultresultorder_order" id="dns_dnspromises_setdefaultresultorder_order">#</a></span></h4> 1527<div class="api_metadata"> 1528<span>Added in: v14.18.0</span> 1529</div> 1530<ul> 1531<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> must be <code>'ipv4first'</code> or <code>'verbatim'</code>.</li> 1532</ul> 1533<p>Set the default value of <code>verbatim</code> in <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> and 1534<a href="#dns_dnspromises_lookup_hostname_options"><code>dnsPromises.lookup()</code></a>. The value could be:</p> 1535<ul> 1536<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li> 1537<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li> 1538</ul> 1539<p>The default is <code>ipv4first</code> and <a href="#dns_dnspromises_setdefaultresultorder_order"><code>dnsPromises.setDefaultResultOrder()</code></a> have 1540higher 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>, 1541<a href="#dns_dnspromises_setdefaultresultorder_order"><code>dnsPromises.setDefaultResultOrder()</code></a> from the main thread won't affect the 1542default dns orders in workers.</p> 1543<h4><code>dnsPromises.setServers(servers)</code><span><a class="mark" href="#dns_dnspromises_setservers_servers" id="dns_dnspromises_setservers_servers">#</a></span></h4> 1544<div class="api_metadata"> 1545<span>Added in: v10.6.0</span> 1546</div> 1547<ul> 1548<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li> 1549</ul> 1550<p>Sets the IP address and port of servers to be used when performing DNS 1551resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted 1552addresses. If the port is the IANA default DNS port (53) it can be omitted.</p> 1553<pre><code class="language-js">dnsPromises.<span class="hljs-title function_">setServers</span>([ 1554 <span class="hljs-string">'4.4.4.4'</span>, 1555 <span class="hljs-string">'[2001:4860:4860::8888]'</span>, 1556 <span class="hljs-string">'4.4.4.4:1053'</span>, 1557 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>, 1558]);</code></pre> 1559<p>An error will be thrown if an invalid address is provided.</p> 1560<p>The <code>dnsPromises.setServers()</code> method must not be called while a DNS query is in 1561progress.</p> 1562<p>This method works much like 1563<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>. 1564That is, if attempting to resolve with the first server provided results in a 1565<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with 1566subsequent servers provided. Fallback DNS servers will only be used if the 1567earlier ones time out or result in some other error.</p> 1568</section><section><h3>Error codes<span><a class="mark" href="#dns_error_codes" id="dns_error_codes">#</a></span></h3> 1569<p>Each DNS query can return one of the following error codes:</p> 1570<ul> 1571<li><code>dns.NODATA</code>: DNS server returned answer with no data.</li> 1572<li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li> 1573<li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li> 1574<li><code>dns.NOTFOUND</code>: Domain name not found.</li> 1575<li><code>dns.NOTIMP</code>: DNS server does not implement requested operation.</li> 1576<li><code>dns.REFUSED</code>: DNS server refused query.</li> 1577<li><code>dns.BADQUERY</code>: Misformatted DNS query.</li> 1578<li><code>dns.BADNAME</code>: Misformatted host name.</li> 1579<li><code>dns.BADFAMILY</code>: Unsupported address family.</li> 1580<li><code>dns.BADRESP</code>: Misformatted DNS reply.</li> 1581<li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li> 1582<li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li> 1583<li><code>dns.EOF</code>: End of file.</li> 1584<li><code>dns.FILE</code>: Error reading file.</li> 1585<li><code>dns.NOMEM</code>: Out of memory.</li> 1586<li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li> 1587<li><code>dns.BADSTR</code>: Misformatted string.</li> 1588<li><code>dns.BADFLAGS</code>: Illegal flags specified.</li> 1589<li><code>dns.NONAME</code>: Given host name is not numeric.</li> 1590<li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li> 1591<li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li> 1592<li><code>dns.LOADIPHLPAPI</code>: Error loading <code>iphlpapi.dll</code>.</li> 1593<li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find <code>GetNetworkParams</code> function.</li> 1594<li><code>dns.CANCELLED</code>: DNS query cancelled.</li> 1595</ul> 1596</section><section><h3>Implementation considerations<span><a class="mark" href="#dns_implementation_considerations" id="dns_implementation_considerations">#</a></span></h3> 1597<p>Although <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> and the various <code>dns.resolve*()/dns.reverse()</code> 1598functions have the same goal of associating a network name with a network 1599address (or vice versa), their behavior is quite different. These differences 1600can have subtle but significant consequences on the behavior of Node.js 1601programs.</p> 1602<h4><code>dns.lookup()</code><span><a class="mark" href="#dns_dns_lookup" id="dns_dns_lookup">#</a></span></h4> 1603<p>Under the hood, <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> uses the same operating system facilities 1604as most other programs. For instance, <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> will almost always 1605resolve a given name the same way as the <code>ping</code> command. On most POSIX-like 1606operating systems, the behavior of the <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> function can be 1607modified 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>, 1608but changing these files will change the behavior of all other 1609programs running on the same operating system.</p> 1610<p>Though the call to <code>dns.lookup()</code> will be asynchronous from JavaScript's 1611perspective, 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 1612on libuv's threadpool. This can have surprising negative performance 1613implications for some applications, see the <a href="cli.html#cli_uv_threadpool_size_size"><code>UV_THREADPOOL_SIZE</code></a> 1614documentation for more information.</p> 1615<p>Various networking APIs will call <code>dns.lookup()</code> internally to resolve 1616host names. If that is an issue, consider resolving the host name to an address 1617using <code>dns.resolve()</code> and using the address instead of a host name. Also, some 1618networking 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>) 1619allow the default resolver, <code>dns.lookup()</code>, to be replaced.</p> 1620<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> 1621<p>These functions are implemented quite differently than <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a>. They 1622do 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 1623network. This network communication is always done asynchronously, and does not 1624use libuv's threadpool.</p> 1625<p>As a result, these functions cannot have the same negative impact on other 1626processing that happens on libuv's threadpool that <a href="#dns_dns_lookup_hostname_options_callback"><code>dns.lookup()</code></a> can have.</p> 1627<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> 1628uses. For instance, <em>they do not use the configuration from <code>/etc/hosts</code></em>.</p></section> 1629 <!-- API END --> 1630 </div> 1631 </div> 1632 </div> 1633 <script> 1634 'use strict'; 1635 { 1636 const kCustomPreference = 'customDarkTheme'; 1637 const userSettings = sessionStorage.getItem(kCustomPreference); 1638 const themeToggleButton = document.getElementById('theme-toggle-btn'); 1639 if (userSettings === null && window.matchMedia) { 1640 const mq = window.matchMedia('(prefers-color-scheme: dark)'); 1641 if ('onchange' in mq) { 1642 function mqChangeListener(e) { 1643 document.body.classList.toggle('dark-mode', e.matches); 1644 } 1645 mq.addEventListener('change', mqChangeListener); 1646 if (themeToggleButton) { 1647 themeToggleButton.addEventListener('click', function() { 1648 mq.removeEventListener('change', mqChangeListener); 1649 }, { once: true }); 1650 } 1651 } 1652 if (mq.matches) { 1653 document.body.classList.add('dark-mode'); 1654 } 1655 } else if (userSettings === 'true') { 1656 document.body.classList.add('dark-mode'); 1657 } 1658 if (themeToggleButton) { 1659 themeToggleButton.hidden = false; 1660 themeToggleButton.addEventListener('click', function() { 1661 sessionStorage.setItem( 1662 kCustomPreference, 1663 document.body.classList.toggle('dark-mode') 1664 ); 1665 }); 1666 } 1667 } 1668 </script> 1669</body> 1670</html> 1671