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