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