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