%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/doc/nodejs/api/
Upload File :
Create Path :
Current File : //usr/share/doc/nodejs/api/dns.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <meta name="nodejs.org:node-version" content="v18.19.1">
  <title>DNS | Node.js v18.19.1 Documentation</title>
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/hljs.css">
  <script async defer src="assets/api.js" type="text/javascript"></script>
  __JS_FLAVORED_DYNAMIC_CSS__
</head>
<body class="alt apidoc" id="api-section-dns">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="index.html" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns active">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>

    </div>

    <div id="column1" data-id="dns" class="interior">
      <header class="header">
        <div class="header-container">
          <h1>Node.js v18.19.1 documentation</h1>
          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
              <path fill="none" d="M0 0h24v24H0z" />
              <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"/>
              <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"/>
            </svg>
            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
              <path d="M0 0h24v24H0z" fill="none" />
              <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"/>
            </svg>
          </button>
        </div>
        <div id="gtoc">
          <ul>
            <li class="pinned-header">Node.js v18.19.1</li>
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Table of contents
      </a>

      <div class="picker"><div class="toc"><ul>
<li><a href="#dns">DNS</a><ul>
<li><a href="#class-dnsresolver">Class: <code>dns.Resolver</code></a><ul>
<li><a href="#resolveroptions"><code>Resolver([options])</code></a></li>
<li><a href="#resolvercancel"><code>resolver.cancel()</code></a></li>
<li><a href="#resolversetlocaladdressipv4-ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</code></a></li>
</ul>
</li>
<li><a href="#dnsgetservers"><code>dns.getServers()</code></a></li>
<li><a href="#dnslookuphostname-options-callback"><code>dns.lookup(hostname[, options], callback)</code></a><ul>
<li><a href="#supported-getaddrinfo-flags">Supported getaddrinfo flags</a></li>
</ul>
</li>
<li><a href="#dnslookupserviceaddress-port-callback"><code>dns.lookupService(address, port, callback)</code></a></li>
<li><a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve(hostname[, rrtype], callback)</code></a></li>
<li><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4(hostname[, options], callback)</code></a></li>
<li><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6(hostname[, options], callback)</code></a></li>
<li><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny(hostname, callback)</code></a></li>
<li><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname(hostname, callback)</code></a></li>
<li><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa(hostname, callback)</code></a></li>
<li><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx(hostname, callback)</code></a></li>
<li><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr(hostname, callback)</code></a></li>
<li><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs(hostname, callback)</code></a></li>
<li><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr(hostname, callback)</code></a></li>
<li><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa(hostname, callback)</code></a></li>
<li><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv(hostname, callback)</code></a></li>
<li><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt(hostname, callback)</code></a></li>
<li><a href="#dnsreverseip-callback"><code>dns.reverse(ip, callback)</code></a></li>
<li><a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder(order)</code></a></li>
<li><a href="#dnsgetdefaultresultorder"><code>dns.getDefaultResultOrder()</code></a></li>
<li><a href="#dnssetserversservers"><code>dns.setServers(servers)</code></a></li>
<li><a href="#dns-promises-api">DNS promises API</a><ul>
<li><a href="#class-dnspromisesresolver">Class: <code>dnsPromises.Resolver</code></a></li>
<li><a href="#resolvercancel_1"><code>resolver.cancel()</code></a></li>
<li><a href="#dnspromisesgetservers"><code>dnsPromises.getServers()</code></a></li>
<li><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup(hostname[, options])</code></a></li>
<li><a href="#dnspromiseslookupserviceaddress-port"><code>dnsPromises.lookupService(address, port)</code></a></li>
<li><a href="#dnspromisesresolvehostname-rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</code></a></li>
<li><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4(hostname[, options])</code></a></li>
<li><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6(hostname[, options])</code></a></li>
<li><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny(hostname)</code></a></li>
<li><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li>
<li><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname(hostname)</code></a></li>
<li><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
<li><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr(hostname)</code></a></li>
<li><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs(hostname)</code></a></li>
<li><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li>
<li><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li>
<li><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li>
<li><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li>
<li><a href="#dnspromisesreverseip"><code>dnsPromises.reverse(ip)</code></a></li>
<li><a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder(order)</code></a></li>
<li><a href="#dnspromisesgetdefaultresultorder"><code>dnsPromises.getDefaultResultOrder()</code></a></li>
<li><a href="#dnspromisessetserversservers"><code>dnsPromises.setServers(servers)</code></a></li>
</ul>
</li>
<li><a href="#error-codes">Error codes</a></li>
<li><a href="#implementation-considerations">Implementation considerations</a><ul>
<li><a href="#dnslookup"><code>dns.lookup()</code></a></li>
<li><a href="#dnsresolve-dnsresolve-and-dnsreverse"><code>dns.resolve()</code>, <code>dns.resolve*()</code>, and <code>dns.reverse()</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div></div>
    </li>
  
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Index
      </a>

      <div class="picker"><ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>

      <li>
        <a href="index.html">Index</a>
      </li>
    </ul>
  
<hr class="line"/>

<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns active">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line"/>

<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>
</div>
    </li>
  
            
    <li class="picker-header">
      <a href="#">
        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
        Other versions
      </a>
      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v18.x/api/dns.html">18.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v17.x/api/dns.html">17.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v16.x/api/dns.html">16.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v15.x/api/dns.html">15.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v14.x/api/dns.html">14.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v13.x/api/dns.html">13.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v12.x/api/dns.html">12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v11.x/api/dns.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/dns.html">10.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/dns.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/dns.html">8.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/dns.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/dns.html">6.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/dns.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/dns.html">4.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/dns.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/dns.html">0.10.x</a></li></ol></div>
    </li>
  
            <li class="picker-header">
              <a href="#">
                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
                Options
              </a>
        
              <div class="picker">
                <ul>
                  <li>
                    <a href="all.html">View on single page</a>
                  </li>
                  <li>
                    <a href="dns.json">View as JSON</a>
                  </li>
                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/dns.md">Edit on GitHub</a></li>    
                </ul>
              </div>
            </li>
          </ul>
        </div>
        <hr>
      </header>

      <details id="toc" open><summary>Table of contents</summary><ul>
<li><a href="#dns">DNS</a><ul>
<li><a href="#class-dnsresolver">Class: <code>dns.Resolver</code></a><ul>
<li><a href="#resolveroptions"><code>Resolver([options])</code></a></li>
<li><a href="#resolvercancel"><code>resolver.cancel()</code></a></li>
<li><a href="#resolversetlocaladdressipv4-ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</code></a></li>
</ul>
</li>
<li><a href="#dnsgetservers"><code>dns.getServers()</code></a></li>
<li><a href="#dnslookuphostname-options-callback"><code>dns.lookup(hostname[, options], callback)</code></a><ul>
<li><a href="#supported-getaddrinfo-flags">Supported getaddrinfo flags</a></li>
</ul>
</li>
<li><a href="#dnslookupserviceaddress-port-callback"><code>dns.lookupService(address, port, callback)</code></a></li>
<li><a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve(hostname[, rrtype], callback)</code></a></li>
<li><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4(hostname[, options], callback)</code></a></li>
<li><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6(hostname[, options], callback)</code></a></li>
<li><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny(hostname, callback)</code></a></li>
<li><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname(hostname, callback)</code></a></li>
<li><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa(hostname, callback)</code></a></li>
<li><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx(hostname, callback)</code></a></li>
<li><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr(hostname, callback)</code></a></li>
<li><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs(hostname, callback)</code></a></li>
<li><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr(hostname, callback)</code></a></li>
<li><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa(hostname, callback)</code></a></li>
<li><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv(hostname, callback)</code></a></li>
<li><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt(hostname, callback)</code></a></li>
<li><a href="#dnsreverseip-callback"><code>dns.reverse(ip, callback)</code></a></li>
<li><a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder(order)</code></a></li>
<li><a href="#dnsgetdefaultresultorder"><code>dns.getDefaultResultOrder()</code></a></li>
<li><a href="#dnssetserversservers"><code>dns.setServers(servers)</code></a></li>
<li><a href="#dns-promises-api">DNS promises API</a><ul>
<li><a href="#class-dnspromisesresolver">Class: <code>dnsPromises.Resolver</code></a></li>
<li><a href="#resolvercancel_1"><code>resolver.cancel()</code></a></li>
<li><a href="#dnspromisesgetservers"><code>dnsPromises.getServers()</code></a></li>
<li><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup(hostname[, options])</code></a></li>
<li><a href="#dnspromiseslookupserviceaddress-port"><code>dnsPromises.lookupService(address, port)</code></a></li>
<li><a href="#dnspromisesresolvehostname-rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</code></a></li>
<li><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4(hostname[, options])</code></a></li>
<li><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6(hostname[, options])</code></a></li>
<li><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny(hostname)</code></a></li>
<li><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li>
<li><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname(hostname)</code></a></li>
<li><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
<li><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr(hostname)</code></a></li>
<li><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs(hostname)</code></a></li>
<li><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li>
<li><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li>
<li><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li>
<li><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li>
<li><a href="#dnspromisesreverseip"><code>dnsPromises.reverse(ip)</code></a></li>
<li><a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder(order)</code></a></li>
<li><a href="#dnspromisesgetdefaultresultorder"><code>dnsPromises.getDefaultResultOrder()</code></a></li>
<li><a href="#dnspromisessetserversservers"><code>dnsPromises.setServers(servers)</code></a></li>
</ul>
</li>
<li><a href="#error-codes">Error codes</a></li>
<li><a href="#implementation-considerations">Implementation considerations</a><ul>
<li><a href="#dnslookup"><code>dns.lookup()</code></a></li>
<li><a href="#dnsresolve-dnsresolve-and-dnsreverse"><code>dns.resolve()</code>, <code>dns.resolve*()</code>, and <code>dns.reverse()</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</details>

      <div id="apicontent">
        <h2>DNS<span><a class="mark" href="#dns" id="dns">#</a></span><a aria-hidden="true" class="legacy" id="dns_dns"></a></h2>
<!--introduced_in=v0.10.0-->

<blockquote>
<p>Stability: 2 - Stable</p>
</blockquote>
<!-- source_link=lib/dns.js -->

<p>The <code>node:dns</code> module enables name resolution. For example, use it to look up IP
addresses of host names.</p>
<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
DNS protocol for lookups. <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> uses the operating system
facilities to perform name resolution. It may not need to perform any network
communication. To perform name resolution the way other applications on the same
system do, use <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>.</p>
<pre><code class="language-js">const dns = require(&#39;node:dns&#39;);

dns.lookup(&#39;example.org&#39;, (err, address, family) =&gt; {
  console.log(&#39;address: %j family: IPv%s&#39;, address, family);
});
// address: &quot;93.184.216.34&quot; family: IPv4
</code></pre>
<p>All other functions in the <code>node:dns</code> module connect to an actual DNS server to
perform name resolution. They will always use the network to perform DNS
queries. These functions do not use the same set of configuration files used by
<a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> (e.g. <code>/etc/hosts</code>). Use these functions to always perform
DNS queries, bypassing other name-resolution facilities.</p>
<pre><code class="language-js">const dns = require(&#39;node:dns&#39;);

dns.resolve4(&#39;archive.org&#39;, (err, addresses) =&gt; {
  if (err) throw err;

  console.log(`addresses: ${JSON.stringify(addresses)}`);

  addresses.forEach((a) =&gt; {
    dns.reverse(a, (err, hostnames) =&gt; {
      if (err) {
        throw err;
      }
      console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
    });
  });
});
</code></pre>
<p>See the <a href="#implementation-considerations">Implementation considerations section</a> for more information.</p>
<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>
<div class="api_metadata">
<span>Added in: v8.3.0</span>
</div><p>An independent resolver for DNS requests.</p>
<p>Creating a new resolver uses the default server settings. Setting
the servers used for a resolver using
<a href="#dnssetserversservers"><code>resolver.setServers()</code></a> does not affect
other resolvers:</p>
<pre><code class="language-js">const { Resolver } = require(&#39;node:dns&#39;);
const resolver = new Resolver();
resolver.setServers([&#39;4.4.4.4&#39;]);

// This request will use the server at 4.4.4.4, independent of global settings.
resolver.resolve4(&#39;example.org&#39;, (err, addresses) =&gt; {
  // ...
});
</code></pre>
<p>The following methods from the <code>node:dns</code> module are available:</p>
<ul>
<li><a href="#dnsgetservers"><code>resolver.getServers()</code></a></li>
<li><a href="#dnsresolvehostname-rrtype-callback"><code>resolver.resolve()</code></a></li>
<li><a href="#dnsresolve4hostname-options-callback"><code>resolver.resolve4()</code></a></li>
<li><a href="#dnsresolve6hostname-options-callback"><code>resolver.resolve6()</code></a></li>
<li><a href="#dnsresolveanyhostname-callback"><code>resolver.resolveAny()</code></a></li>
<li><a href="#dnsresolvecaahostname-callback"><code>resolver.resolveCaa()</code></a></li>
<li><a href="#dnsresolvecnamehostname-callback"><code>resolver.resolveCname()</code></a></li>
<li><a href="#dnsresolvemxhostname-callback"><code>resolver.resolveMx()</code></a></li>
<li><a href="#dnsresolvenaptrhostname-callback"><code>resolver.resolveNaptr()</code></a></li>
<li><a href="#dnsresolvenshostname-callback"><code>resolver.resolveNs()</code></a></li>
<li><a href="#dnsresolveptrhostname-callback"><code>resolver.resolvePtr()</code></a></li>
<li><a href="#dnsresolvesoahostname-callback"><code>resolver.resolveSoa()</code></a></li>
<li><a href="#dnsresolvesrvhostname-callback"><code>resolver.resolveSrv()</code></a></li>
<li><a href="#dnsresolvetxthostname-callback"><code>resolver.resolveTxt()</code></a></li>
<li><a href="#dnsreverseip-callback"><code>resolver.reverse()</code></a></li>
<li><a href="#dnssetserversservers"><code>resolver.setServers()</code></a></li>
</ul>
<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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v16.7.0, v14.18.0</td>
<td><p>The <code>options</code> object now accepts a <code>tries</code> option.</p>
</td></tr>
<tr><td>v12.18.3</td>
<td><p>The constructor now accepts an <code>options</code> object. The single supported option is <code>timeout</code>.</p>
</td></tr>
<tr><td>v8.3.0</td>
<td><p><span>Added in: v8.3.0</span></p>
</td></tr>
</table>
</details>
</div><p>Create a new resolver.</p>
<ul>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>timeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> Query timeout in milliseconds, or <code>-1</code> to use the
default timeout.</li>
<li><code>tries</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> The number of tries the resolver will try contacting
each name server before giving up. <strong>Default:</strong> <code>4</code></li>
</ul>
</li>
</ul>
<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>
<div class="api_metadata">
<span>Added in: v8.3.0</span>
</div><p>Cancel all outstanding DNS queries made by this resolver. The corresponding
callbacks will be called with an error with code <code>ECANCELLED</code>.</p>
<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>
<div class="api_metadata">
<span>Added in: v15.1.0, v14.17.0</span>
</div><ul>
<li><code>ipv4</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A string representation of an IPv4 address.
<strong>Default:</strong> <code>&#39;0.0.0.0&#39;</code></li>
<li><code>ipv6</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A string representation of an IPv6 address.
<strong>Default:</strong> <code>&#39;::0&#39;</code></li>
</ul>
<p>The resolver instance will send its requests from the specified IP address.
This allows programs to specify outbound interfaces when used on multi-homed
systems.</p>
<p>If a v4 or v6 address is not specified, it is set to the default and the
operating system will choose a local address automatically.</p>
<p>The resolver will use the v4 local address when making requests to IPv4 DNS
servers, and the v6 local address when making requests to IPv6 DNS servers.
The <code>rrtype</code> of resolution requests has no impact on the local address used.</p>
</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>
<div class="api_metadata">
<span>Added in: v0.11.3</span>
</div><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
that are currently configured for DNS resolution. A string will include a port
section if a custom port is used.</p>
<!-- eslint-disable semi-->

<pre><code class="language-js">[
  &#39;4.4.4.4&#39;,
  &#39;2001:4860:4860::8888&#39;,
  &#39;4.4.4.4:1053&#39;,
  &#39;[2001:4860:4860::8888]:1053&#39;,
]
</code></pre>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.4.0</td>
<td><p>For compatibility with <code>node:net</code>, when passing an option object the <code>family</code> option can be the string <code>&#39;IPv4&#39;</code> or the string <code>&#39;IPv6&#39;</code>.</p>
</td></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v17.0.0</td>
<td><p>The <code>verbatim</code> options defaults to <code>true</code> now.</p>
</td></tr>
<tr><td>v8.5.0</td>
<td><p>The <code>verbatim</code> option is supported now.</p>
</td></tr>
<tr><td>v1.2.0</td>
<td><p>The <code>all</code> option is supported now.</p>
</td></tr>
<tr><td>v0.1.90</td>
<td><p><span>Added in: v0.1.90</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>options</code> {integer | Object}<ul>
<li><code>family</code> {integer|string} The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. For
backward compatibility reasons,<code>&#39;IPv4&#39;</code> and <code>&#39;IPv6&#39;</code> are interpreted as <code>4</code>
and <code>6</code> respectively. The value <code>0</code> indicates that IPv4 and IPv6 addresses
are both returned. <strong>Default:</strong> <code>0</code>.</li>
<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> One or more <a href="#supported-getaddrinfo-flags">supported <code>getaddrinfo</code> flags</a>. Multiple
flags may be passed by bitwise <code>OR</code>ing their values.</li>
<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> When <code>true</code>, the callback returns all resolved addresses in
an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> When <code>true</code>, the callback receives IPv4 and IPv6
addresses in the order the DNS resolver returned them. When <code>false</code>,
IPv4 addresses are placed before IPv6 addresses.
<strong>Default:</strong> <code>true</code> (addresses are not reordered). Default value is
configurable using <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> or
<a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>.</li>
</ul>
</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A string representation of an IPv4 or IPv6 address.</li>
<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> <code>4</code> or <code>6</code>, denoting the family of <code>address</code>, or <code>0</code> if
the address is not an IPv4 or IPv6 address. <code>0</code> is a likely indicator of a
bug in the name resolution service used by the operating system.</li>
</ul>
</li>
</ul>
<p>Resolves a host name (e.g. <code>&#39;nodejs.org&#39;</code>) into the first found A (IPv4) or
AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is <code>0</code> or not provided, then
IPv4 and IPv6 addresses are both returned if found.</p>
<p>With the <code>all</code> option set to <code>true</code>, the arguments for <code>callback</code> change to
<code>(err, addresses)</code>, with <code>addresses</code> being an array of objects with the
properties <code>address</code> and <code>family</code>.</p>
<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.
Keep in mind that <code>err.code</code> will be set to <code>&#39;ENOTFOUND&#39;</code> not only when
the host name does not exist but also when the lookup fails in other ways
such as no available file descriptors.</p>
<p><code>dns.lookup()</code> does not necessarily have anything to do with the DNS protocol.
The implementation uses an operating system facility that can associate names
with addresses and vice versa. This implementation can have subtle but
important consequences on the behavior of any Node.js program. Please take some
time to consult the <a href="#implementation-considerations">Implementation considerations section</a> before using
<code>dns.lookup()</code>.</p>
<p>Example usage:</p>
<pre><code class="language-js">const dns = require(&#39;node:dns&#39;);
const options = {
  family: 6,
  hints: dns.ADDRCONFIG | dns.V4MAPPED,
};
dns.lookup(&#39;example.com&#39;, options, (err, address, family) =&gt;
  console.log(&#39;address: %j family: IPv%s&#39;, address, family));
// address: &quot;2606:2800:220:1:248:1893:25c8:1946&quot; family: IPv6

// When options.all is true, the result will be an Array.
options.all = true;
dns.lookup(&#39;example.com&#39;, options, (err, addresses) =&gt;
  console.log(&#39;addresses: %j&#39;, addresses));
// addresses: [{&quot;address&quot;:&quot;2606:2800:220:1:248:1893:25c8:1946&quot;,&quot;family&quot;:6}]
</code></pre>
<p>If this method is invoked as its <a href="util.html#utilpromisifyoriginal"><code>util.promisify()</code></a>ed version, and <code>all</code>
is not set to <code>true</code>, it returns a <code>Promise</code> for an <code>Object</code> with <code>address</code> and
<code>family</code> properties.</p>
<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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.13.0, v12.17.0</td>
<td><p>Added support for the <code>dns.ALL</code> flag.</p>
</td></tr>
</table>
</details>
</div><p>The following flags can be passed as hints to <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>.</p>
<ul>
<li><code>dns.ADDRCONFIG</code>: Limits returned address types to the types of non-loopback
addresses configured on the system. For example, IPv4 addresses are only
returned if the current system has at least one IPv4 address configured.</li>
<li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses were
found, then return IPv4 mapped IPv6 addresses. It is not supported
on some operating systems (e.g. FreeBSD 10.1).</li>
<li><code>dns.ALL</code>: If <code>dns.V4MAPPED</code> is specified, return resolved IPv6 addresses as
well as IPv4 mapped IPv6 addresses.</li>
</ul>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.11.14</td>
<td><p><span>Added in: v0.11.14</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> e.g. <code>example.com</code></li>
<li><code>service</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> e.g. <code>http</code></li>
</ul>
</li>
</ul>
<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
the operating system&#39;s underlying <code>getnameinfo</code> implementation.</p>
<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>
will be thrown.</p>
<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>
<pre><code class="language-js">const dns = require(&#39;node:dns&#39;);
dns.lookupService(&#39;127.0.0.1&#39;, 22, (err, hostname, service) =&gt; {
  console.log(hostname, service);
  // Prints: localhost ssh
});
</code></pre>
<p>If this method is invoked as its <a href="util.html#utilpromisifyoriginal"><code>util.promisify()</code></a>ed version, it returns a
<code>Promise</code> for an <code>Object</code> with <code>hostname</code> and <code>service</code> properties.</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.1.27</td>
<td><p><span>Added in: v0.1.27</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host name to resolve.</li>
<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Resource record type. <strong>Default:</strong> <code>&#39;A&#39;</code>.</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>records</code> {string[] | Object[] | Object}</li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve a host name (e.g. <code>&#39;nodejs.org&#39;</code>) into an array
of the resource records. The <code>callback</code> function has arguments
<code>(err, records)</code>. When successful, <code>records</code> will be an array of resource
records. The type and structure of individual results varies based on <code>rrtype</code>:</p>
<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>&#39;A&#39;</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">&lt;string&gt;</a></td>
<td><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4()</code></a></td>
</tr>
<tr>
<td><code>&#39;AAAA&#39;</code></td>
<td>IPv6 addresses</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></td>
<td><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6()</code></a></td>
</tr>
<tr>
<td><code>&#39;ANY&#39;</code></td>
<td>any records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></td>
<td><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny()</code></a></td>
</tr>
<tr>
<td><code>&#39;CAA&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa()</code></a></td>
</tr>
<tr>
<td><code>&#39;CNAME&#39;</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">&lt;string&gt;</a></td>
<td><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname()</code></a></td>
</tr>
<tr>
<td><code>&#39;MX&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx()</code></a></td>
</tr>
<tr>
<td><code>&#39;NAPTR&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr()</code></a></td>
</tr>
<tr>
<td><code>&#39;NS&#39;</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">&lt;string&gt;</a></td>
<td><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs()</code></a></td>
</tr>
<tr>
<td><code>&#39;PTR&#39;</code></td>
<td>pointer records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></td>
<td><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr()</code></a></td>
</tr>
<tr>
<td><code>&#39;SOA&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa()</code></a></td>
</tr>
<tr>
<td><code>&#39;SRV&#39;</code></td>
<td>service records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></td>
<td><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv()</code></a></td>
</tr>
<tr>
<td><code>&#39;TXT&#39;</code></td>
<td>text records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></td>
<td><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt()</code></a></td>
</tr>
</tbody></table>
<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
<a href="#error-codes">DNS error codes</a>.</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v7.2.0</td>
<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p>
</td></tr>
<tr><td>v0.1.16</td>
<td><p><span>Added in: v0.1.16</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host name to resolve.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Retrieves the Time-To-Live value (TTL) of each record.
When <code>true</code>, the callback receives an array of
<code>{ address: &#39;1.2.3.4&#39;, ttl: 60 }</code> objects rather than an array of strings,
with the TTL expressed in seconds.</li>
</ul>
</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> {string[] | Object[]}</li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve a IPv4 addresses (<code>A</code> records) for the
<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function
will contain an array of IPv4 addresses (e.g.
<code>[&#39;74.125.79.104&#39;, &#39;74.125.79.105&#39;, &#39;74.125.79.106&#39;]</code>).</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v7.2.0</td>
<td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>.</p>
</td></tr>
<tr><td>v0.1.16</td>
<td><p><span>Added in: v0.1.16</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host name to resolve.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Retrieve the Time-To-Live value (TTL) of each record.
When <code>true</code>, the callback receives an array of
<code>{ address: &#39;0:1:2:3:4:5:6:7&#39;, ttl: 60 }</code> objects rather than an array of
strings, with the TTL expressed in seconds.</li>
</ul>
</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> {string[] | Object[]}</li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function
will contain an array of IPv6 addresses.</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>ret</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).
The <code>ret</code> argument passed to the <code>callback</code> function will be an array containing
various types of records. Each object has a property <code>type</code> that indicates the
type of the current record. And depending on the <code>type</code>, additional properties
will be present on the object:</p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Properties</th>
</tr>
</thead>
<tbody><tr>
<td><code>&#39;A&#39;</code></td>
<td><code>address</code>/<code>ttl</code></td>
</tr>
<tr>
<td><code>&#39;AAAA&#39;</code></td>
<td><code>address</code>/<code>ttl</code></td>
</tr>
<tr>
<td><code>&#39;CNAME&#39;</code></td>
<td><code>value</code></td>
</tr>
<tr>
<td><code>&#39;MX&#39;</code></td>
<td>Refer to <a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx()</code></a></td>
</tr>
<tr>
<td><code>&#39;NAPTR&#39;</code></td>
<td>Refer to <a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr()</code></a></td>
</tr>
<tr>
<td><code>&#39;NS&#39;</code></td>
<td><code>value</code></td>
</tr>
<tr>
<td><code>&#39;PTR&#39;</code></td>
<td><code>value</code></td>
</tr>
<tr>
<td><code>&#39;SOA&#39;</code></td>
<td>Refer to <a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa()</code></a></td>
</tr>
<tr>
<td><code>&#39;SRV&#39;</code></td>
<td>Refer to <a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv()</code></a></td>
</tr>
<tr>
<td><code>&#39;TXT&#39;</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: [&#39;...&#39;], type: &#39;TXT&#39; }</code></td>
</tr>
</tbody></table>
<p>Here is an example of the <code>ret</code> object passed to the callback:</p>
<!-- eslint-disable semi -->

<pre><code class="language-js">[ { type: &#39;A&#39;, address: &#39;127.0.0.1&#39;, ttl: 299 },
  { type: &#39;CNAME&#39;, value: &#39;example.com&#39; },
  { type: &#39;MX&#39;, exchange: &#39;alt4.aspmx.l.example.com&#39;, priority: 50 },
  { type: &#39;NS&#39;, value: &#39;ns1.example.com&#39; },
  { type: &#39;TXT&#39;, entries: [ &#39;v=spf1 include:_spf.example.com ~all&#39; ] },
  { type: &#39;SOA&#39;,
    nsname: &#39;ns1.example.com&#39;,
    hostmaster: &#39;admin.example.com&#39;,
    serial: 156696742,
    refresh: 900,
    retry: 900,
    expire: 1800,
    minttl: 60 } ]
</code></pre>
<p>DNS server operators may choose not to respond to <code>ANY</code>
queries. It may be better to call individual methods like <a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4()</code></a>,
<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>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.3.2</td>
<td><p><span>Added in: v0.3.2</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. The
<code>addresses</code> argument passed to the <code>callback</code> function
will contain an array of canonical name records available for the <code>hostname</code>
(e.g. <code>[&#39;bar.example.com&#39;]</code>).</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v15.0.0, v14.17.0</td>
<td><p><span>Added in: v15.0.0, v14.17.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. The
<code>addresses</code> argument passed to the <code>callback</code> function
will contain an array of certification authority authorization records
available for the <code>hostname</code> (e.g. <code>[{critical: 0, iodef: &#39;mailto:pki@example.com&#39;}, {critical: 128, issue: &#39;pki.example.com&#39;}]</code>).</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.1.27</td>
<td><p><span>Added in: v0.1.27</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
contain an array of objects containing both a <code>priority</code> and <code>exchange</code>
property (e.g. <code>[{priority: 10, exchange: &#39;mx.example.com&#39;}, ...]</code>).</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.9.12</td>
<td><p><span>Added in: v0.9.12</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve regular expression-based records (<code>NAPTR</code>
records) for the <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code>
function will contain an array of objects with the following properties:</p>
<ul>
<li><code>flags</code></li>
<li><code>service</code></li>
<li><code>regexp</code></li>
<li><code>replacement</code></li>
<li><code>order</code></li>
<li><code>preference</code></li>
</ul>
<!-- eslint-skip -->

<pre><code class="language-js">{
  flags: &#39;s&#39;,
  service: &#39;SIP+D2U&#39;,
  regexp: &#39;&#39;,
  replacement: &#39;_sip._udp.example.com&#39;,
  order: 30,
  preference: 100
}
</code></pre>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.1.90</td>
<td><p><span>Added in: v0.1.90</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
contain an array of name server records available for <code>hostname</code>
(e.g. <code>[&#39;ns1.example.com&#39;, &#39;ns2.example.com&#39;]</code>).</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v6.0.0</td>
<td><p><span>Added in: v6.0.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
be an array of strings containing the reply records.</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.11.10</td>
<td><p><span>Added in: v0.11.10</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
the <code>hostname</code>. The <code>address</code> argument passed to the <code>callback</code> function will
be an object with the following properties:</p>
<ul>
<li><code>nsname</code></li>
<li><code>hostmaster</code></li>
<li><code>serial</code></li>
<li><code>refresh</code></li>
<li><code>retry</code></li>
<li><code>expire</code></li>
<li><code>minttl</code></li>
</ul>
<!-- eslint-skip -->

<pre><code class="language-js">{
  nsname: &#39;ns.example.com&#39;,
  hostmaster: &#39;root.example.com&#39;,
  serial: 2013101809,
  refresh: 10000,
  retry: 2400,
  expire: 604800,
  minttl: 3600
}
</code></pre>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.1.27</td>
<td><p><span>Added in: v0.1.27</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
<code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> function will
be an array of objects with the following properties:</p>
<ul>
<li><code>priority</code></li>
<li><code>weight</code></li>
<li><code>port</code></li>
<li><code>name</code></li>
</ul>
<!-- eslint-skip -->

<pre><code class="language-js">{
  priority: 10,
  weight: 5,
  port: 21223,
  name: &#39;service.example.com&#39;
}
</code></pre>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v18.0.0</td>
<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>
<tr><td>v0.1.27</td>
<td><p><span>Added in: v0.1.27</span></p>
</td></tr>
</table>
</details>
</div><!--lint disable no-undefined-references list-item-bullet-indent-->

<ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[][]&gt;</a></li>
</ul>
</li>
</ul>
<!--lint enable no-undefined-references list-item-bullet-indent-->

<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
<code>hostname</code>. The <code>records</code> argument passed to the <code>callback</code> function is a
two-dimensional array of the text records available for <code>hostname</code> (e.g.
<code>[ [&#39;v=spf1 ip4:0.0.0.0 &#39;, &#39;~all&#39; ] ]</code>). Each sub-array contains TXT chunks of
one record. Depending on the use case, these could be either joined together or
treated separately.</p>
</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>
<div class="api_metadata">
<span>Added in: v0.1.16</span>
</div><ul>
<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a><ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li>
<li><code>hostnames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
</li>
</ul>
<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
array of host names.</p>
<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 <a href="#error-codes">DNS error codes</a>.</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v17.0.0</td>
<td><p>Changed default value to <code>verbatim</code>.</p>
</td></tr>
<tr><td>v16.4.0, v14.18.0</td>
<td><p><span>Added in: v16.4.0, v14.18.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> must be <code>&#39;ipv4first&#39;</code> or <code>&#39;verbatim&#39;</code>.</li>
</ul>
<p>Set the default value of <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and
<a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
<ul>
<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
</ul>
<p>The default is <code>verbatim</code> and <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> have higher
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>,
<a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> from the main thread won&#39;t affect the default
dns orders in workers.</p>
</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>
<div class="api_metadata">
<span>Added in: v18.17.0</span>
</div><p>Get the default value for <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and
<a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
<ul>
<li><code>ipv4first</code>: for <code>verbatim</code> defaulting to <code>false</code>.</li>
<li><code>verbatim</code>: for <code>verbatim</code> defaulting to <code>true</code>.</li>
</ul>
</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>
<div class="api_metadata">
<span>Added in: v0.11.3</span>
</div><ul>
<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li>
</ul>
<p>Sets the IP address and port of servers to be used when performing DNS
resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted
addresses. If the port is the IANA default DNS port (53) it can be omitted.</p>
<pre><code class="language-js">dns.setServers([
  &#39;4.4.4.4&#39;,
  &#39;[2001:4860:4860::8888]&#39;,
  &#39;4.4.4.4:1053&#39;,
  &#39;[2001:4860:4860::8888]:1053&#39;,
]);
</code></pre>
<p>An error will be thrown if an invalid address is provided.</p>
<p>The <code>dns.setServers()</code> method must not be called while a DNS query is in
progress.</p>
<p>The <a href="#dnssetserversservers"><code>dns.setServers()</code></a> method affects only <a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve()</code></a>,
<code>dns.resolve*()</code> and <a href="#dnsreverseip-callback"><code>dns.reverse()</code></a> (and specifically <em>not</em>
<a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>).</p>
<p>This method works much like
<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
That is, if attempting to resolve with the first server provided results in a
<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with
subsequent servers provided. Fallback DNS servers will only be used if the
earlier ones time out or result in some other error.</p>
</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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v15.0.0</td>
<td><p>Exposed as <code>require(&#39;dns/promises&#39;)</code>.</p>
</td></tr>
<tr><td>v11.14.0, v10.17.0</td>
<td><p>This API is no longer experimental.</p>
</td></tr>
<tr><td>v10.6.0</td>
<td><p><span>Added in: v10.6.0</span></p>
</td></tr>
</table>
</details>
</div><p>The <code>dns.promises</code> API provides an alternative set of asynchronous DNS methods
that return <code>Promise</code> objects rather than using callbacks. The API is accessible
via <code>require(&#39;node:dns&#39;).promises</code> or <code>require(&#39;node:dns/promises&#39;)</code>.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><p>An independent resolver for DNS requests.</p>
<p>Creating a new resolver uses the default server settings. Setting
the servers used for a resolver using
<a href="#dnspromisessetserversservers"><code>resolver.setServers()</code></a> does not affect
other resolvers:</p>
<pre><code class="language-js">const { Resolver } = require(&#39;node:dns&#39;).promises;
const resolver = new Resolver();
resolver.setServers([&#39;4.4.4.4&#39;]);

// This request will use the server at 4.4.4.4, independent of global settings.
resolver.resolve4(&#39;example.org&#39;).then((addresses) =&gt; {
  // ...
});

// Alternatively, the same code can be written using async-await style.
(async function() {
  const addresses = await resolver.resolve4(&#39;example.org&#39;);
})();
</code></pre>
<p>The following methods from the <code>dnsPromises</code> API are available:</p>
<ul>
<li><a href="#dnspromisesgetservers"><code>resolver.getServers()</code></a></li>
<li><a href="#dnspromisesresolvehostname-rrtype"><code>resolver.resolve()</code></a></li>
<li><a href="#dnspromisesresolve4hostname-options"><code>resolver.resolve4()</code></a></li>
<li><a href="#dnspromisesresolve6hostname-options"><code>resolver.resolve6()</code></a></li>
<li><a href="#dnspromisesresolveanyhostname"><code>resolver.resolveAny()</code></a></li>
<li><a href="#dnspromisesresolvecaahostname"><code>resolver.resolveCaa()</code></a></li>
<li><a href="#dnspromisesresolvecnamehostname"><code>resolver.resolveCname()</code></a></li>
<li><a href="#dnspromisesresolvemxhostname"><code>resolver.resolveMx()</code></a></li>
<li><a href="#dnspromisesresolvenaptrhostname"><code>resolver.resolveNaptr()</code></a></li>
<li><a href="#dnspromisesresolvenshostname"><code>resolver.resolveNs()</code></a></li>
<li><a href="#dnspromisesresolveptrhostname"><code>resolver.resolvePtr()</code></a></li>
<li><a href="#dnspromisesresolvesoahostname"><code>resolver.resolveSoa()</code></a></li>
<li><a href="#dnspromisesresolvesrvhostname"><code>resolver.resolveSrv()</code></a></li>
<li><a href="#dnspromisesresolvetxthostname"><code>resolver.resolveTxt()</code></a></li>
<li><a href="#dnspromisesreverseip"><code>resolver.reverse()</code></a></li>
<li><a href="#dnspromisessetserversservers"><code>resolver.setServers()</code></a></li>
</ul>
<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>
<div class="api_metadata">
<span>Added in: v15.3.0, v14.17.0</span>
</div><p>Cancel all outstanding DNS queries made by this resolver. The corresponding
promises will be rejected with an error with the code <code>ECANCELLED</code>.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></li>
</ul>
<p>Returns an array of IP address strings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
that are currently configured for DNS resolution. A string will include a port
section if a custom port is used.</p>
<!-- eslint-disable semi-->

<pre><code class="language-js">[
  &#39;4.4.4.4&#39;,
  &#39;2001:4860:4860::8888&#39;,
  &#39;4.4.4.4:1053&#39;,
  &#39;[2001:4860:4860::8888]:1053&#39;,
]
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>options</code> {integer | Object}<ul>
<li><code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> The record family. Must be <code>4</code>, <code>6</code>, or <code>0</code>. The value
<code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong>
<code>0</code>.</li>
<li><code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> One or more <a href="#supported-getaddrinfo-flags">supported <code>getaddrinfo</code> flags</a>. Multiple
flags may be passed by bitwise <code>OR</code>ing their values.</li>
<li><code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> When <code>true</code>, the <code>Promise</code> is resolved with all addresses in
an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
<li><code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> When <code>true</code>, the <code>Promise</code> is resolved with IPv4 and
IPv6 addresses in the order the DNS resolver returned them. When <code>false</code>,
IPv4 addresses are placed before IPv6 addresses.
<strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is
expected to change in the not too distant future. Default value is
configurable using <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> or
<a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>. New code should use <code>{ verbatim: true }</code>.</li>
</ul>
</li>
</ul>
<p>Resolves a host name (e.g. <code>&#39;nodejs.org&#39;</code>) into the first found A (IPv4) or
AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided, then IPv4
and IPv6 addresses are both returned if found.</p>
<p>With the <code>all</code> option set to <code>true</code>, the <code>Promise</code> is resolved with <code>addresses</code>
being an array of objects with the properties <code>address</code> and <code>family</code>.</p>
<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>
is the error code.
Keep in mind that <code>err.code</code> will be set to <code>&#39;ENOTFOUND&#39;</code> not only when
the host name does not exist but also when the lookup fails in other ways
such as no available file descriptors.</p>
<p><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a> does not necessarily have anything to do with the DNS
protocol. The implementation uses an operating system facility that can
associate names with addresses and vice versa. This implementation can have
subtle but important consequences on the behavior of any Node.js program. Please
take some time to consult the <a href="#implementation-considerations">Implementation considerations section</a> before
using <code>dnsPromises.lookup()</code>.</p>
<p>Example usage:</p>
<pre><code class="language-js">const dns = require(&#39;node:dns&#39;);
const dnsPromises = dns.promises;
const options = {
  family: 6,
  hints: dns.ADDRCONFIG | dns.V4MAPPED,
};

dnsPromises.lookup(&#39;example.com&#39;, options).then((result) =&gt; {
  console.log(&#39;address: %j family: IPv%s&#39;, result.address, result.family);
  // address: &quot;2606:2800:220:1:248:1893:25c8:1946&quot; family: IPv6
});

// When options.all is true, the result will be an Array.
options.all = true;
dnsPromises.lookup(&#39;example.com&#39;, options).then((result) =&gt; {
  console.log(&#39;addresses: %j&#39;, result);
  // addresses: [{&quot;address&quot;:&quot;2606:2800:220:1:248:1893:25c8:1946&quot;,&quot;family&quot;:6}]
});
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
<p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
the operating system&#39;s underlying <code>getnameinfo</code> implementation.</p>
<p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</code>
will be thrown.</p>
<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>
is the error code.</p>
<pre><code class="language-js">const dnsPromises = require(&#39;node:dns&#39;).promises;
dnsPromises.lookupService(&#39;127.0.0.1&#39;, 22).then((result) =&gt; {
  console.log(result.hostname, result.service);
  // Prints: localhost ssh
});
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host name to resolve.</li>
<li><code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Resource record type. <strong>Default:</strong> <code>&#39;A&#39;</code>.</li>
</ul>
<p>Uses the DNS protocol to resolve a host name (e.g. <code>&#39;nodejs.org&#39;</code>) into an array
of the resource records. When successful, the <code>Promise</code> is resolved with an
array of resource records. The type and structure of individual results vary
based on <code>rrtype</code>:</p>
<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>&#39;A&#39;</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">&lt;string&gt;</a></td>
<td><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4()</code></a></td>
</tr>
<tr>
<td><code>&#39;AAAA&#39;</code></td>
<td>IPv6 addresses</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></td>
<td><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6()</code></a></td>
</tr>
<tr>
<td><code>&#39;ANY&#39;</code></td>
<td>any records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></td>
<td><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny()</code></a></td>
</tr>
<tr>
<td><code>&#39;CAA&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa()</code></a></td>
</tr>
<tr>
<td><code>&#39;CNAME&#39;</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">&lt;string&gt;</a></td>
<td><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname()</code></a></td>
</tr>
<tr>
<td><code>&#39;MX&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx()</code></a></td>
</tr>
<tr>
<td><code>&#39;NAPTR&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr()</code></a></td>
</tr>
<tr>
<td><code>&#39;NS&#39;</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">&lt;string&gt;</a></td>
<td><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs()</code></a></td>
</tr>
<tr>
<td><code>&#39;PTR&#39;</code></td>
<td>pointer records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></td>
<td><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr()</code></a></td>
</tr>
<tr>
<td><code>&#39;SOA&#39;</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">&lt;Object&gt;</a></td>
<td><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa()</code></a></td>
</tr>
<tr>
<td><code>&#39;SRV&#39;</code></td>
<td>service records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></td>
<td><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv()</code></a></td>
</tr>
<tr>
<td><code>&#39;TXT&#39;</code></td>
<td>text records</td>
<td><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a></td>
<td><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt()</code></a></td>
</tr>
</tbody></table>
<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>
is one of the <a href="#error-codes">DNS error codes</a>.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host name to resolve.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Retrieve the Time-To-Live value (TTL) of each record.
When <code>true</code>, the <code>Promise</code> is resolved with an array of
<code>{ address: &#39;1.2.3.4&#39;, ttl: 60 }</code> objects rather than an array of strings,
with the TTL expressed in seconds.</li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve IPv4 addresses (<code>A</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv4
addresses (e.g. <code>[&#39;74.125.79.104&#39;, &#39;74.125.79.105&#39;, &#39;74.125.79.106&#39;]</code>).</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host name to resolve.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Retrieve the Time-To-Live value (TTL) of each record.
When <code>true</code>, the <code>Promise</code> is resolved with an array of
<code>{ address: &#39;0:1:2:3:4:5:6:7&#39;, ttl: 60 }</code> objects rather than an array of
strings, with the TTL expressed in seconds.</li>
</ul>
</li>
</ul>
<p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv6
addresses.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> query).
On success, the <code>Promise</code> is resolved with an array containing various types of
records. Each object has a property <code>type</code> that indicates the type of the
current record. And depending on the <code>type</code>, additional properties will be
present on the object:</p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Properties</th>
</tr>
</thead>
<tbody><tr>
<td><code>&#39;A&#39;</code></td>
<td><code>address</code>/<code>ttl</code></td>
</tr>
<tr>
<td><code>&#39;AAAA&#39;</code></td>
<td><code>address</code>/<code>ttl</code></td>
</tr>
<tr>
<td><code>&#39;CNAME&#39;</code></td>
<td><code>value</code></td>
</tr>
<tr>
<td><code>&#39;MX&#39;</code></td>
<td>Refer to <a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx()</code></a></td>
</tr>
<tr>
<td><code>&#39;NAPTR&#39;</code></td>
<td>Refer to <a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr()</code></a></td>
</tr>
<tr>
<td><code>&#39;NS&#39;</code></td>
<td><code>value</code></td>
</tr>
<tr>
<td><code>&#39;PTR&#39;</code></td>
<td><code>value</code></td>
</tr>
<tr>
<td><code>&#39;SOA&#39;</code></td>
<td>Refer to <a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa()</code></a></td>
</tr>
<tr>
<td><code>&#39;SRV&#39;</code></td>
<td>Refer to <a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv()</code></a></td>
</tr>
<tr>
<td><code>&#39;TXT&#39;</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: [&#39;...&#39;], type: &#39;TXT&#39; }</code></td>
</tr>
</tbody></table>
<p>Here is an example of the result object:</p>
<!-- eslint-disable semi -->

<pre><code class="language-js">[ { type: &#39;A&#39;, address: &#39;127.0.0.1&#39;, ttl: 299 },
  { type: &#39;CNAME&#39;, value: &#39;example.com&#39; },
  { type: &#39;MX&#39;, exchange: &#39;alt4.aspmx.l.example.com&#39;, priority: 50 },
  { type: &#39;NS&#39;, value: &#39;ns1.example.com&#39; },
  { type: &#39;TXT&#39;, entries: [ &#39;v=spf1 include:_spf.example.com ~all&#39; ] },
  { type: &#39;SOA&#39;,
    nsname: &#39;ns1.example.com&#39;,
    hostmaster: &#39;admin.example.com&#39;,
    serial: 156696742,
    refresh: 900,
    retry: 900,
    expire: 1800,
    minttl: 60 } ]
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v15.0.0, v14.17.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. On success,
the <code>Promise</code> is resolved with an array of objects containing available
certification authority authorization records available for the <code>hostname</code>
(e.g. <code>[{critical: 0, iodef: &#39;mailto:pki@example.com&#39;},{critical: 128, issue: &#39;pki.example.com&#39;}]</code>).</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. On success,
the <code>Promise</code> is resolved with an array of canonical name records available for
the <code>hostname</code> (e.g. <code>[&#39;bar.example.com&#39;]</code>).</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects
containing both a <code>priority</code> and <code>exchange</code> property (e.g.
<code>[{priority: 10, exchange: &#39;mx.example.com&#39;}, ...]</code>).</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve regular expression-based records (<code>NAPTR</code>
records) for the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array
of objects with the following properties:</p>
<ul>
<li><code>flags</code></li>
<li><code>service</code></li>
<li><code>regexp</code></li>
<li><code>replacement</code></li>
<li><code>order</code></li>
<li><code>preference</code></li>
</ul>
<!-- eslint-skip -->

<pre><code class="language-js">{
  flags: &#39;s&#39;,
  service: &#39;SIP+D2U&#39;,
  regexp: &#39;&#39;,
  replacement: &#39;_sip._udp.example.com&#39;,
  order: 30,
  preference: 100
}
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of name server
records available for <code>hostname</code> (e.g.
<code>[&#39;ns1.example.com&#39;, &#39;ns2.example.com&#39;]</code>).</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of strings
containing the reply records.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an object with the
following properties:</p>
<ul>
<li><code>nsname</code></li>
<li><code>hostmaster</code></li>
<li><code>serial</code></li>
<li><code>refresh</code></li>
<li><code>retry</code></li>
<li><code>expire</code></li>
<li><code>minttl</code></li>
</ul>
<!-- eslint-skip -->

<pre><code class="language-js">{
  nsname: &#39;ns.example.com&#39;,
  hostmaster: &#39;root.example.com&#39;,
  serial: 2013101809,
  refresh: 10000,
  retry: 2400,
  expire: 604800,
  minttl: 3600
}
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects with
the following properties:</p>
<ul>
<li><code>priority</code></li>
<li><code>weight</code></li>
<li><code>port</code></li>
<li><code>name</code></li>
</ul>
<!-- eslint-skip -->

<pre><code class="language-js">{
  priority: 10,
  weight: 5,
  port: 21223,
  name: &#39;service.example.com&#39;
}
</code></pre>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
<code>hostname</code>. On success, the <code>Promise</code> is resolved with a two-dimensional array
of the text records available for <code>hostname</code> (e.g.
<code>[ [&#39;v=spf1 ip4:0.0.0.0 &#39;, &#39;~all&#39; ] ]</code>). Each sub-array contains TXT chunks of
one record. Depending on the use case, these could be either joined together or
treated separately.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
array of host names.</p>
<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>
is one of the <a href="#error-codes">DNS error codes</a>.</p>
<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>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v17.0.0</td>
<td><p>Changed default value to <code>verbatim</code>.</p>
</td></tr>
<tr><td>v16.4.0, v14.18.0</td>
<td><p><span>Added in: v16.4.0, v14.18.0</span></p>
</td></tr>
</table>
</details>
</div><ul>
<li><code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> must be <code>&#39;ipv4first&#39;</code> or <code>&#39;verbatim&#39;</code>.</li>
</ul>
<p>Set the default value of <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and
<a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could be:</p>
<ul>
<li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
<li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
</ul>
<p>The default is <code>verbatim</code> and <a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder()</code></a> have
higher 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>,
<a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder()</code></a> from the main thread won&#39;t affect the
default dns orders in workers.</p>
<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>
<div class="api_metadata">
<span>Added in: v18.17.0</span>
</div><p>Get the value of <code>dnsOrder</code>.</p>
<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>
<div class="api_metadata">
<span>Added in: v10.6.0</span>
</div><ul>
<li><code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted addresses</li>
</ul>
<p>Sets the IP address and port of servers to be used when performing DNS
resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a> formatted
addresses. If the port is the IANA default DNS port (53) it can be omitted.</p>
<pre><code class="language-js">dnsPromises.setServers([
  &#39;4.4.4.4&#39;,
  &#39;[2001:4860:4860::8888]&#39;,
  &#39;4.4.4.4:1053&#39;,
  &#39;[2001:4860:4860::8888]:1053&#39;,
]);
</code></pre>
<p>An error will be thrown if an invalid address is provided.</p>
<p>The <code>dnsPromises.setServers()</code> method must not be called while a DNS query is in
progress.</p>
<p>This method works much like
<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
That is, if attempting to resolve with the first server provided results in a
<code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve with
subsequent servers provided. Fallback DNS servers will only be used if the
earlier ones time out or result in some other error.</p>
</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>
<p>Each DNS query can return one of the following error codes:</p>
<ul>
<li><code>dns.NODATA</code>: DNS server returned an answer with no data.</li>
<li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li>
<li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li>
<li><code>dns.NOTFOUND</code>: Domain name not found.</li>
<li><code>dns.NOTIMP</code>: DNS server does not implement the requested operation.</li>
<li><code>dns.REFUSED</code>: DNS server refused query.</li>
<li><code>dns.BADQUERY</code>: Misformatted DNS query.</li>
<li><code>dns.BADNAME</code>: Misformatted host name.</li>
<li><code>dns.BADFAMILY</code>: Unsupported address family.</li>
<li><code>dns.BADRESP</code>: Misformatted DNS reply.</li>
<li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li>
<li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li>
<li><code>dns.EOF</code>: End of file.</li>
<li><code>dns.FILE</code>: Error reading file.</li>
<li><code>dns.NOMEM</code>: Out of memory.</li>
<li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li>
<li><code>dns.BADSTR</code>: Misformatted string.</li>
<li><code>dns.BADFLAGS</code>: Illegal flags specified.</li>
<li><code>dns.NONAME</code>: Given host name is not numeric.</li>
<li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li>
<li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li>
<li><code>dns.LOADIPHLPAPI</code>: Error loading <code>iphlpapi.dll</code>.</li>
<li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find <code>GetNetworkParams</code> function.</li>
<li><code>dns.CANCELLED</code>: DNS query cancelled.</li>
</ul>
<p>The <code>dnsPromises</code> API also exports the above error codes, e.g., <code>dnsPromises.NODATA</code>.</p>
</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>
<p>Although <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and the various <code>dns.resolve*()/dns.reverse()</code>
functions have the same goal of associating a network name with a network
address (or vice versa), their behavior is quite different. These differences
can have subtle but significant consequences on the behavior of Node.js
programs.</p>
<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>
<p>Under the hood, <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> uses the same operating system facilities
as most other programs. For instance, <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> will almost always
resolve a given name the same way as the <code>ping</code> command. On most POSIX-like
operating systems, the behavior of the <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> function can be
modified 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>,
but changing these files will change the behavior of all other
programs running on the same operating system.</p>
<p>Though the call to <code>dns.lookup()</code> will be asynchronous from JavaScript&#39;s
perspective, 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
on libuv&#39;s threadpool. This can have surprising negative performance
implications for some applications, see the <a href="cli.html#uv_threadpool_sizesize"><code>UV_THREADPOOL_SIZE</code></a>
documentation for more information.</p>
<p>Various networking APIs will call <code>dns.lookup()</code> internally to resolve
host names. If that is an issue, consider resolving the host name to an address
using <code>dns.resolve()</code> and using the address instead of a host name. Also, some
networking 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>)
allow the default resolver, <code>dns.lookup()</code>, to be replaced.</p>
<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>
<p>These functions are implemented quite differently than <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>. They
do 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
network. This network communication is always done asynchronously and does not
use libuv&#39;s threadpool.</p>
<p>As a result, these functions cannot have the same negative impact on other
processing that happens on libuv&#39;s threadpool that <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> can have.</p>
<p>They do not use the same set of configuration files that <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>
uses. For instance, they do not use the configuration from <code>/etc/hosts</code>.</p>
</section>
        <!-- API END -->
      </div>
    </div>
  </div>
</body>
</html>

Zerion Mini Shell 1.0