Lines Matching +full:code +full:-
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width">
6 <meta name="nodejs.org:node-version" content="v18.20.1">
15 <body class="alt apidoc" id="api-section-dns">
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>
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…
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>
92 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
96 <div id="column1" data-id="dns" class="interior">
98 <div class="header-container">
100 …<button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-la…
101 <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
103 …-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.6…
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-2…
106 <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
108 …-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.4…
114 <li class="pinned-header">Node.js v18.20.1</li>
116 <li class="picker-header">
118 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
125 <li><a href="#class-dnsresolver">Class: <code>dns.Resolver</code></a>
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])</cod…
132 <li><a href="#dnsgetservers"><code>dns.getServers()</code></a></li>
133 <li><a href="#dnslookuphostname-options-callback"><code>dns.lookup(hostname[, options], callback)</…
135 <li><a href="#supported-getaddrinfo-flags">Supported getaddrinfo flags</a></li>
138 <li><a href="#dnslookupserviceaddress-port-callback"><code>dns.lookupService(address, port, callbac…
139 <li><a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve(hostname[, rrtype], callback)</…
140 <li><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4(hostname[, options], callbac…
141 <li><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6(hostname[, options], callbac…
142 <li><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny(hostname, callback)</code></a></…
143 <li><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname(hostname, callback)</code></…
144 <li><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa(hostname, callback)</code></a></…
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></…
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></…
149 <li><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa(hostname, callback)</code></a></…
150 <li><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv(hostname, callback)</code></a></…
151 <li><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt(hostname, callback)</code></a></…
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>
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])</cod…
162 <li><a href="#dnspromiseslookupserviceaddress-port"><code>dnsPromises.lookupService(address, port)<…
163 <li><a href="#dnspromisesresolvehostname-rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</cod…
164 <li><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4(hostname[, options])<…
165 <li><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6(hostname[, options])<…
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><…
169 <li><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
170 <li><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr(hostname)</code></a><…
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 …><a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder(order)</…
178 <li><a href="#dnspromisesgetdefaultresultorder"><code>dnsPromises.getDefaultResultOrder()</code></a…
179 <li><a href="#dnspromisessetserversservers"><code>dnsPromises.setServers(servers)</code></a></li>
182 <li><a href="#error-codes">Error codes</a></li>
183 <li><a href="#implementation-considerations">Implementation considerations</a>
185 <li><a href="#dnslookup"><code>dns.lookup()</code></a></li>
186 …a href="#dnsresolve-dnsresolve-and-dnsreverse"><code>dns.resolve()</code>, <code>dns.resolve*()</c…
195 <li class="picker-header">
197 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
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>
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…
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>
275 <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code reposito…
280 <li class="picker-header">
282 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
285 …<div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/dns.ht…
286 <li><a href="https://nodejs.org/docs/latest-v20.x/api/dns.html">20.x <b>LTS</b></a></li>
287 <li><a href="https://nodejs.org/docs/latest-v19.x/api/dns.html">19.x</a></li>
288 <li><a href="https://nodejs.org/docs/latest-v18.x/api/dns.html">18.x <b>LTS</b></a></li>
289 <li><a href="https://nodejs.org/docs/latest-v17.x/api/dns.html">17.x</a></li>
290 <li><a href="https://nodejs.org/docs/latest-v16.x/api/dns.html">16.x</a></li>
291 <li><a href="https://nodejs.org/docs/latest-v15.x/api/dns.html">15.x</a></li>
292 <li><a href="https://nodejs.org/docs/latest-v14.x/api/dns.html">14.x</a></li>
293 <li><a href="https://nodejs.org/docs/latest-v13.x/api/dns.html">13.x</a></li>
294 <li><a href="https://nodejs.org/docs/latest-v12.x/api/dns.html">12.x</a></li>
295 <li><a href="https://nodejs.org/docs/latest-v11.x/api/dns.html">11.x</a></li>
296 <li><a href="https://nodejs.org/docs/latest-v10.x/api/dns.html">10.x</a></li>
297 <li><a href="https://nodejs.org/docs/latest-v9.x/api/dns.html">9.x</a></li>
298 <li><a href="https://nodejs.org/docs/latest-v8.x/api/dns.html">8.x</a></li>
299 <li><a href="https://nodejs.org/docs/latest-v7.x/api/dns.html">7.x</a></li>
300 <li><a href="https://nodejs.org/docs/latest-v6.x/api/dns.html">6.x</a></li>
301 <li><a href="https://nodejs.org/docs/latest-v5.x/api/dns.html">5.x</a></li>
302 <li><a href="https://nodejs.org/docs/latest-v4.x/api/dns.html">4.x</a></li>
303 <li><a href="https://nodejs.org/docs/latest-v0.12.x/api/dns.html">0.12.x</a></li>
304 <li><a href="https://nodejs.org/docs/latest-v0.10.x/api/dns.html">0.10.x</a></li></ol></div>
307 <li class="picker-header">
309 … <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span>
333 <li><a href="#class-dnsresolver">Class: <code>dns.Resolver</code></a>
335 <li><a href="#resolveroptions"><code>Resolver([options])</code></a></li>
336 <li><a href="#resolvercancel"><code>resolver.cancel()</code></a></li>
337 <li><a href="#resolversetlocaladdressipv4-ipv6"><code>resolver.setLocalAddress([ipv4][, ipv6])</cod…
340 <li><a href="#dnsgetservers"><code>dns.getServers()</code></a></li>
341 <li><a href="#dnslookuphostname-options-callback"><code>dns.lookup(hostname[, options], callback)</…
343 <li><a href="#supported-getaddrinfo-flags">Supported getaddrinfo flags</a></li>
346 <li><a href="#dnslookupserviceaddress-port-callback"><code>dns.lookupService(address, port, callbac…
347 <li><a href="#dnsresolvehostname-rrtype-callback"><code>dns.resolve(hostname[, rrtype], callback)</…
348 <li><a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4(hostname[, options], callbac…
349 <li><a href="#dnsresolve6hostname-options-callback"><code>dns.resolve6(hostname[, options], callbac…
350 <li><a href="#dnsresolveanyhostname-callback"><code>dns.resolveAny(hostname, callback)</code></a></…
351 <li><a href="#dnsresolvecnamehostname-callback"><code>dns.resolveCname(hostname, callback)</code></…
352 <li><a href="#dnsresolvecaahostname-callback"><code>dns.resolveCaa(hostname, callback)</code></a></…
353 <li><a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx(hostname, callback)</code></a></li>
354 <li><a href="#dnsresolvenaptrhostname-callback"><code>dns.resolveNaptr(hostname, callback)</code></…
355 <li><a href="#dnsresolvenshostname-callback"><code>dns.resolveNs(hostname, callback)</code></a></li>
356 <li><a href="#dnsresolveptrhostname-callback"><code>dns.resolvePtr(hostname, callback)</code></a></…
357 <li><a href="#dnsresolvesoahostname-callback"><code>dns.resolveSoa(hostname, callback)</code></a></…
358 <li><a href="#dnsresolvesrvhostname-callback"><code>dns.resolveSrv(hostname, callback)</code></a></…
359 <li><a href="#dnsresolvetxthostname-callback"><code>dns.resolveTxt(hostname, callback)</code></a></…
360 <li><a href="#dnsreverseip-callback"><code>dns.reverse(ip, callback)</code></a></li>
361 <li><a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder(order)</code></a></li>
362 <li><a href="#dnsgetdefaultresultorder"><code>dns.getDefaultResultOrder()</code></a></li>
363 <li><a href="#dnssetserversservers"><code>dns.setServers(servers)</code></a></li>
364 <li><a href="#dns-promises-api">DNS promises API</a>
366 <li><a href="#class-dnspromisesresolver">Class: <code>dnsPromises.Resolver</code></a></li>
367 <li><a href="#resolvercancel_1"><code>resolver.cancel()</code></a></li>
368 <li><a href="#dnspromisesgetservers"><code>dnsPromises.getServers()</code></a></li>
369 <li><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup(hostname[, options])</cod…
370 <li><a href="#dnspromiseslookupserviceaddress-port"><code>dnsPromises.lookupService(address, port)<…
371 <li><a href="#dnspromisesresolvehostname-rrtype"><code>dnsPromises.resolve(hostname[, rrtype])</cod…
372 <li><a href="#dnspromisesresolve4hostname-options"><code>dnsPromises.resolve4(hostname[, options])<…
373 <li><a href="#dnspromisesresolve6hostname-options"><code>dnsPromises.resolve6(hostname[, options])<…
374 <li><a href="#dnspromisesresolveanyhostname"><code>dnsPromises.resolveAny(hostname)</code></a></li>
375 <li><a href="#dnspromisesresolvecaahostname"><code>dnsPromises.resolveCaa(hostname)</code></a></li>
376 <li><a href="#dnspromisesresolvecnamehostname"><code>dnsPromises.resolveCname(hostname)</code></a><…
377 <li><a href="#dnspromisesresolvemxhostname"><code>dnsPromises.resolveMx(hostname)</code></a></li>
378 <li><a href="#dnspromisesresolvenaptrhostname"><code>dnsPromises.resolveNaptr(hostname)</code></a><…
379 <li><a href="#dnspromisesresolvenshostname"><code>dnsPromises.resolveNs(hostname)</code></a></li>
380 <li><a href="#dnspromisesresolveptrhostname"><code>dnsPromises.resolvePtr(hostname)</code></a></li>
381 <li><a href="#dnspromisesresolvesoahostname"><code>dnsPromises.resolveSoa(hostname)</code></a></li>
382 <li><a href="#dnspromisesresolvesrvhostname"><code>dnsPromises.resolveSrv(hostname)</code></a></li>
383 <li><a href="#dnspromisesresolvetxthostname"><code>dnsPromises.resolveTxt(hostname)</code></a></li>
384 <li><a href="#dnspromisesreverseip"><code>dnsPromises.reverse(ip)</code></a></li>
385 …><a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder(order)</…
386 <li><a href="#dnspromisesgetdefaultresultorder"><code>dnsPromises.getDefaultResultOrder()</code></a…
387 <li><a href="#dnspromisessetserversservers"><code>dnsPromises.setServers(servers)</code></a></li>
390 <li><a href="#error-codes">Error codes</a></li>
391 <li><a href="#implementation-considerations">Implementation considerations</a>
393 <li><a href="#dnslookup"><code>dns.lookup()</code></a></li>
394 …a href="#dnsresolve-dnsresolve-and-dnsreverse"><code>dns.resolve()</code>, <code>dns.resolve*()</c…
402 …<h2>DNS<span><a class="mark" href="#dns" id="dns">#</a></span><a aria-hidden="true" class="legacy"…
404 …tability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</…
405 <p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/dns.js">…
406 <p>The <code>node:dns</code> module enables name resolution. For example, use it to look up IP
409 DNS protocol for lookups. <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></…
412 system do, use <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>.</p>
413 <pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-buil…
415 …n class="hljs-title function_">lookup</span>(<span class="hljs-string">'example.org'</span>, <span…
416 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
418 <span class="hljs-comment">// address: "93.184.216.34" family: IPv4</span></code> <button class="co…
419 <p>All other functions in the <code>node:dns</code> module connect to an actual DNS server to
422 <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> (e.g. <code>/etc/hosts<…
423 DNS queries, bypassing other name-resolution facilities.</p>
424 <pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-buil…
426 … class="hljs-title function_">resolve4</span>(<span class="hljs-string">'archive.org'</span>, <spa…
427 <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">throw</span> err;
429 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hlj…
431 …addresses.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span cla…
432 …dns.<span class="hljs-title function_">reverse</span>(a, <span class="hljs-function">(<span class=…
433 <span class="hljs-keyword">if</span> (err) {
434 <span class="hljs-keyword">throw</span> err;
436 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hlj…
439 });</code> <button class="copy-button">copy</button></pre>
440 <p>See the <a href="#implementation-considerations">Implementation considerations section</a> for m…
441 …ection><h3>Class: <code>dns.Resolver</code><span><a class="mark" href="#class-dnsresolver" id="cla…
448 <a href="#dnssetserversservers"><code>resolver.setServers()</code></a> does not affect
450 …code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_"…
451 <span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span clas…
452 resolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'<…
454 <span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global se…
455 … class="hljs-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>, <spa…
456 <span class="hljs-comment">// ...</span>
457 });</code> <button class="copy-button">copy</button></pre>
458 <p>The following methods from the <code>node:dns</code> module are available:</p>
460 <li><a href="#dnsgetservers"><code>resolver.getServers()</code></a></li>
461 <li><a href="#dnsresolvehostname-rrtype-callback"><code>resolver.resolve()</code></a></li>
462 <li><a href="#dnsresolve4hostname-options-callback"><code>resolver.resolve4()</code></a></li>
463 <li><a href="#dnsresolve6hostname-options-callback"><code>resolver.resolve6()</code></a></li>
464 <li><a href="#dnsresolveanyhostname-callback"><code>resolver.resolveAny()</code></a></li>
465 <li><a href="#dnsresolvecaahostname-callback"><code>resolver.resolveCaa()</code></a></li>
466 <li><a href="#dnsresolvecnamehostname-callback"><code>resolver.resolveCname()</code></a></li>
467 <li><a href="#dnsresolvemxhostname-callback"><code>resolver.resolveMx()</code></a></li>
468 <li><a href="#dnsresolvenaptrhostname-callback"><code>resolver.resolveNaptr()</code></a></li>
469 <li><a href="#dnsresolvenshostname-callback"><code>resolver.resolveNs()</code></a></li>
470 <li><a href="#dnsresolveptrhostname-callback"><code>resolver.resolvePtr()</code></a></li>
471 <li><a href="#dnsresolvesoahostname-callback"><code>resolver.resolveSoa()</code></a></li>
472 <li><a href="#dnsresolvesrvhostname-callback"><code>resolver.resolveSrv()</code></a></li>
473 <li><a href="#dnsresolvetxthostname-callback"><code>resolver.resolveTxt()</code></a></li>
474 <li><a href="#dnsreverseip-callback"><code>resolver.reverse()</code></a></li>
475 <li><a href="#dnssetserversservers"><code>resolver.setServers()</code></a></li>
477 <h4><code>Resolver([options])</code><span><a class="mark" href="#resolveroptions" id="resolveroptio…
483 <td><p>The <code>options</code> object now accepts a <code>tries</code> option.</p></td></tr>
485 …d><p>The constructor now accepts an <code>options</code> object. The single supported option is <c…
493 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
495 …code>timeout</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
497 <li><code>tries</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
498 each name server before giving up. <strong>Default:</strong> <code>4</code></li>
502 <h4><code>resolver.cancel()</code><span><a class="mark" href="#resolvercancel" id="resolvercancel">…
507 callbacks will be called with an error with code <code>ECANCELLED</code>.</p>
508 …code>resolver.setLocalAddress([ipv4][, ipv6])</code><span><a class="mark" href="#resolversetlocala…
513 <li><code>ipv4</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
514 <strong>Default:</strong> <code>'0.0.0.0'</code></li>
515 <li><code>ipv6</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
516 <strong>Default:</strong> <code>'::0'</code></li>
519 This allows programs to specify outbound interfaces when used on multi-homed
525 The <code>rrtype</code> of resolution requests has no impact on the local address used.</p>
526 …ection><section><h3><code>dns.getServers()</code><span><a class="mark" href="#dnsgetservers" id="d…
531 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Strin…
533 …rings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
536 <!-- eslint-disable semi-->
537 <pre><code class="language-js">[
538 <span class="hljs-string">'4.4.4.4'</span>,
539 <span class="hljs-string">'2001:4860:4860::8888'</span>,
540 <span class="hljs-string">'4.4.4.4:1053'</span>,
541 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
542 ]</code> <button class="copy-button">copy</button></pre>
543 …code>dns.lookup(hostname[, options], callback)</code><span><a class="mark" href="#dnslookuphostnam…
549 …code>node:net</code>, when passing an option object the <code>family</code> option can be the stri…
551 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
553 <td><p>The <code>verbatim</code> options defaults to <code>true</code> now.</p></td></tr>
555 <td><p>The <code>verbatim</code> option is supported now.</p></td></tr>
557 <td><p>The <code>all</code> option is supported now.</p></td></tr>
564 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
565 …code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
567 …code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
568 backward compatibility reasons,<code>'IPv4'</code> and <code>'IPv6'</code> are interpreted as <code…
569 and <code>6</code> respectively. The value <code>0</code> indicates that IPv4 and IPv6 addresses
570 are both returned. <strong>Default:</strong> <code>0</code>.</li>
571 …code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
572 flags may be passed by bitwise <code>OR</code>ing their values.</li>
573 …code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B…
574 an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
575 …code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
576 addresses in the order the DNS resolver returned them. When <code>false</code>,
578 <strong>Default:</strong> <code>true</code> (addresses are not reordered). Default value is
579 configurable using <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code…
580 <a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>.</li>
583 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
585 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
586 <li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
587 …code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
588 the address is not an IPv4 or IPv6 address. <code>0</code> is a likely indicator of a
593 <p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or
594 AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
595 integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is <code>0</cod…
597 <p>With the <code>all</code> option set to <code>true</code>, the arguments for <code>callback</cod…
598 <code>(err, addresses)</code>, with <code>addresses</code> being an array of objects with the
599 properties <code>address</code> and <code>family</code>.</p>
600 …n error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object, w…
601 Keep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when
604 <p><code>dns.lookup()</code> does not necessarily have anything to do with the DNS protocol.
608 time to consult the <a href="#implementation-considerations">Implementation considerations section<…
609 <code>dns.lookup()</code>.</p>
611 <pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-buil…
612 <span class="hljs-keyword">const</span> options = {
613 <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>,
614 …<span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<spa…
616 …ss="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options, <…
617 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
618 <span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span>
620 <span class="hljs-comment">// When options.all is true, the result will be an Array.</span>
621 options.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>;
622 …ss="hljs-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options, <…
623 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
624 …span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":…
625 …s <a href="util.html#utilpromisifyoriginal"><code>util.promisify()</code></a>ed version, and <code…
626 is not set to <code>true</code>, it returns a <code>Promise</code> for an <code>Object</code> with …
627 <code>family</code> properties.</p>
628 …gs<span><a class="mark" href="#supported-getaddrinfo-flags" id="supported-getaddrinfo-flags">#</a>…
634 <td><p>Added support for the <code>dns.ALL</code> flag.</p></td></tr>
638 …s can be passed as hints to <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code…
640 <li><code>dns.ADDRCONFIG</code>: Limits returned address types to the types of non-loopback
643 <li><code>dns.V4MAPPED</code>: If the IPv6 family was specified, but no IPv6 addresses were
646 <li><code>dns.ALL</code>: If <code>dns.V4MAPPED</code> is specified, return resolved IPv6 addresses…
649 …code>dns.lookupService(address, port, callback)</code><span><a class="mark" href="#dnslookupservic…
655 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
662 <li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
663 <li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
664 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
666 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
667 …code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
668 …code>service</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
672 <p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
673 the operating system's underlying <code>getnameinfo</code> implementation.</p>
674 <p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
675 The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</co…
677 …n error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object, w…
678 <pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-buil…
679 …-title function_">lookupService</span>(<span class="hljs-string">'127.0.0.1'</span>, <span class="…
680 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
681 <span class="hljs-comment">// Prints: localhost ssh</span>
682 });</code> <button class="copy-button">copy</button></pre>
683 …d is invoked as its <a href="util.html#utilpromisifyoriginal"><code>util.promisify()</code></a>ed …
684 <code>Promise</code> for an <code>Object</code> with <code>hostname</code> and <code>service</code>…
685 …code>dns.resolve(hostname[, rrtype], callback)</code><span><a class="mark" href="#dnsresolvehostna…
691 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
698 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
699 …code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
700 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
702 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
703 …code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
707 <p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array
708 of the resource records. The <code>callback</code> function has arguments
709 <code>(err, records)</code>. When successful, <code>records</code> will be an array of resource
710 records. The type and structure of individual results varies based on <code>rrtype</code>:</p>
794 …code>rrtype</code></th><th><code>records</code> contains</th><th>Result type</th><th>Shorthand met…
795 <p>On error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object…
796 <a href="#error-codes">DNS error codes</a>.</p>
797 …code>dns.resolve4(hostname[, options], callback)</code><span><a class="mark" href="#dnsresolve4hos…
803 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
805 <td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>…
812 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
813 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
815 …code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B…
816 When <code>true</code>, the callback receives an array of
817 <code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings,
821 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
823 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
824 …code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
828 <p>Uses the DNS protocol to resolve a IPv4 addresses (<code>A</code> records) for the
829 <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> func…
831 <code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>
832 …code>dns.resolve6(hostname[, options], callback)</code><span><a class="mark" href="#dnsresolve6hos…
838 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
840 <td><p>This method now supports passing <code>options</code>, specifically <code>options.ttl</code>…
847 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
848 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
850 …code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B…
851 When <code>true</code>, the callback receives an array of
852 <code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of
856 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
858 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
859 …code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_struct…
863 <p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
864 <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> func…
866 …code>dns.resolveAny(hostname, callback)</code><span><a class="mark" href="#dnsresolveanyhostname-c…
872 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
877 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
878 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
880 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
881 <li><code>ret</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
885 <p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> q…
886 The <code>ret</code> argument passed to the <code>callback</code> function will be an array contain…
887 various types of records. Each object has a property <code>type</code> that indicates the
888 type of the current record. And depending on the <code>type</code>, additional properties
939 …code>'A'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'AAAA'</code>…
940 <p>Here is an example of the <code>ret</code> object passed to the callback:</p>
941 <!-- eslint-disable semi -->
942 …code class="language-js">[ { <span class="hljs-attr">type</span>: <span class="hljs-string">'A'</s…
943 …<span class="hljs-attr">type</span>: <span class="hljs-string">'CNAME'</span>, <span class="hljs-a…
944 …-attr">type</span>: <span class="hljs-string">'MX'</span>, <span class="hljs-attr">exchange</span>…
945 …{ <span class="hljs-attr">type</span>: <span class="hljs-string">'NS'</span>, <span class="hljs-at…
946 …span class="hljs-attr">type</span>: <span class="hljs-string">'TXT'</span>, <span class="hljs-attr…
947 { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>,
948 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>,
949 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>,
950 <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>,
951 <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>,
952 <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>,
953 <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>,
954 …<span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code> <button clas…
955 <p>DNS server operators may choose not to respond to <code>ANY</code>
956 … individual methods like <a href="#dnsresolve4hostname-options-callback"><code>dns.resolve4()</cod…
957 <a href="#dnsresolvemxhostname-callback"><code>dns.resolveMx()</code></a>, and so on. For more deta…
958 …code>dns.resolveCname(hostname, callback)</code><span><a class="mark" href="#dnsresolvecnamehostna…
964 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
971 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
972 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
974 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
975 <li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_st…
979 <p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. The
980 <code>addresses</code> argument passed to the <code>callback</code> function
981 will contain an array of canonical name records available for the <code>hostname</code>
982 (e.g. <code>['bar.example.com']</code>).</p>
983 …code>dns.resolveCaa(hostname, callback)</code><span><a class="mark" href="#dnsresolvecaahostname-c…
989 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
996 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
997 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
999 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1000 <li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
1004 <p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. The
1005 <code>addresses</code> argument passed to the <code>callback</code> function
1007 …e for the <code>hostname</code> (e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'}, {crit…
1008 …code>dns.resolveMx(hostname, callback)</code><span><a class="mark" href="#dnsresolvemxhostname-cal…
1014 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1021 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1022 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1024 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1025 <li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen…
1029 <p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
1030 <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> func…
1031 contain an array of objects containing both a <code>priority</code> and <code>exchange</code>
1032 property (e.g. <code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>
1033 …code>dns.resolveNaptr(hostname, callback)</code><span><a class="mark" href="#dnsresolvenaptrhostna…
1039 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1046 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1047 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1049 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1050 <li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen…
1054 <p>Uses the DNS protocol to resolve regular expression-based records (<code>NAPTR</code>
1055 records) for the <code>hostname</code>. The <code>addresses</code> argument passed to the <code>cal…
1058 <li><code>flags</code></li>
1059 <li><code>service</code></li>
1060 <li><code>regexp</code></li>
1061 <li><code>replacement</code></li>
1062 <li><code>order</code></li>
1063 <li><code>preference</code></li>
1065 <!-- eslint-skip -->
1066 <pre><code class="language-js">{
1067 <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>,
1068 <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>,
1069 <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>,
1070 …<span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</spa…
1071 <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>,
1072 <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span>
1073 }</code> <button class="copy-button">copy</button></pre>
1074 …code>dns.resolveNs(hostname, callback)</code><span><a class="mark" href="#dnsresolvenshostname-cal…
1080 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1087 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1088 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1090 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1091 <li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_st…
1095 <p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
1096 <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> func…
1097 contain an array of name server records available for <code>hostname</code>
1098 (e.g. <code>['ns1.example.com', 'ns2.example.com']</code>).</p>
1099 …code>dns.resolvePtr(hostname, callback)</code><span><a class="mark" href="#dnsresolveptrhostname-c…
1105 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1112 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1113 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1115 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1116 <li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_st…
1120 <p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
1121 <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> func…
1123 …code>dns.resolveSoa(hostname, callback)</code><span><a class="mark" href="#dnsresolvesoahostname-c…
1129 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1136 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1137 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1139 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1140 <li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
1144 <p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
1145 the <code>hostname</code>. The <code>address</code> argument passed to the <code>callback</code> fu…
1148 <li><code>nsname</code></li>
1149 <li><code>hostmaster</code></li>
1150 <li><code>serial</code></li>
1151 <li><code>refresh</code></li>
1152 <li><code>retry</code></li>
1153 <li><code>expire</code></li>
1154 <li><code>minttl</code></li>
1156 <!-- eslint-skip -->
1157 <pre><code class="language-js">{
1158 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>,
1159 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>,
1160 <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>,
1161 <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>,
1162 <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>,
1163 <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>,
1164 <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span>
1165 }</code> <button class="copy-button">copy</button></pre>
1166 …code>dns.resolveSrv(hostname, callback)</code><span><a class="mark" href="#dnsresolvesrvhostname-c…
1172 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1179 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1180 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1182 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1183 <li><code>addresses</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen…
1187 <p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
1188 <code>hostname</code>. The <code>addresses</code> argument passed to the <code>callback</code> func…
1191 <li><code>priority</code></li>
1192 <li><code>weight</code></li>
1193 <li><code>port</code></li>
1194 <li><code>name</code></li>
1196 <!-- eslint-skip -->
1197 <pre><code class="language-js">{
1198 <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>,
1199 <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>,
1200 <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>,
1201 <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span>
1202 }</code> <button class="copy-button">copy</button></pre>
1203 …code>dns.resolveTxt(hostname, callback)</code><span><a class="mark" href="#dnsresolvetxthostname-c…
1209 …callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instea…
1215 <!--lint disable no-undefined-references list-item-bullet-indent-->
1217 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1218 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1220 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1221 <li><code>records</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
1225 <!--lint enable no-undefined-references list-item-bullet-indent-->
1226 <p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
1227 <code>hostname</code>. The <code>records</code> argument passed to the <code>callback</code> functi…
1228 two-dimensional array of the text records available for <code>hostname</code> (e.g.
1229 <code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of
1232 …on><h3><code>dns.reverse(ip, callback)</code><span><a class="mark" href="#dnsreverseip-callback" i…
1237 <li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
1238 <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc…
1240 <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo…
1241 <li><code>hostnames</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_st…
1247 <p>On error, <code>err</code> is an <a href="errors.html#class-error"><code>Error</code></a> object…
1248 one of the <a href="#error-codes">DNS error codes</a>.</p>
1249 …code>dns.setDefaultResultOrder(order)</code><span><a class="mark" href="#dnssetdefaultresultordero…
1255 <td><p>Changed default value to <code>verbatim</code>.</p></td></tr>
1262 …code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
1264 <p>Set the default value of <code>verbatim</code> in <a href="#dnslookuphostname-options-callback">…
1265 <a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could…
1267 <li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
1268 <li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
1270 <p>The default is <code>verbatim</code> and <a href="#dnssetdefaultresultorderorder"><code>dns.setD…
1271 priority than <a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>. When …
1272 <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code></a> from the main…
1274 …h3><code>dns.getDefaultResultOrder()</code><span><a class="mark" href="#dnsgetdefaultresultorder" …
1278 …p>Get the default value for <code>verbatim</code> in <a href="#dnslookuphostname-options-callback"…
1279 <a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could…
1281 <li><code>ipv4first</code>: for <code>verbatim</code> defaulting to <code>false</code>.</li>
1282 <li><code>verbatim</code>: for <code>verbatim</code> defaulting to <code>true</code>.</li>
1284 …tion><h3><code>dns.setServers(servers)</code><span><a class="mark" href="#dnssetserversservers" id…
1289 …code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
1292 resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/r…
1294 <pre><code class="language-js">dns.<span class="hljs-title function_">setServers</span>([
1295 <span class="hljs-string">'4.4.4.4'</span>,
1296 <span class="hljs-string">'[2001:4860:4860::8888]'</span>,
1297 <span class="hljs-string">'4.4.4.4:1053'</span>,
1298 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
1299 ]);</code> <button class="copy-button">copy</button></pre>
1301 <p>The <code>dns.setServers()</code> method must not be called while a DNS query is in
1303 …versservers"><code>dns.setServers()</code></a> method affects only <a href="#dnsresolvehostname-rr…
1304 <code>dns.resolve*()</code> and <a href="#dnsreverseip-callback"><code>dns.reverse()</code></a> (an…
1305 <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a>).</p>
1307 <a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
1309 <code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve…
1312 …DNS promises API<span><a class="mark" href="#dns-promises-api" id="dns-promises-api">#</a></span><…
1318 <td><p>Exposed as <code>require('dns/promises')</code>.</p></td></tr>
1326 <p>The <code>dns.promises</code> API provides an alternative set of asynchronous DNS methods
1327 that return <code>Promise</code> objects rather than using callbacks. The API is accessible
1328 via <code>require('node:dns').promises</code> or <code>require('node:dns/promises')</code>.</p>
1329 …lass: <code>dnsPromises.Resolver</code><span><a class="mark" href="#class-dnspromisesresolver" id=…
1336 <a href="#dnspromisessetserversservers"><code>resolver.setServers()</code></a> does not affect
1338 …code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_"…
1339 <span class="hljs-keyword">const</span> resolver = <span class="hljs-keyword">new</span> <span clas…
1340 resolver.<span class="hljs-title function_">setServers</span>([<span class="hljs-string">'4.4.4.4'<…
1342 <span class="hljs-comment">// This request will use the server at 4.4.4.4, independent of global se…
1343 …-title function_">resolve4</span>(<span class="hljs-string">'example.org'</span>).<span class="hlj…
1344 <span class="hljs-comment">// ...</span>
1347 <span class="hljs-comment">// Alternatively, the same code can be written using async-await style.<…
1348 (<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span>(<span class="hl…
1349 …-keyword">const</span> addresses = <span class="hljs-keyword">await</span> resolver.<span class="h…
1350 })();</code> <button class="copy-button">copy</button></pre>
1351 <p>The following methods from the <code>dnsPromises</code> API are available:</p>
1353 <li><a href="#dnspromisesgetservers"><code>resolver.getServers()</code></a></li>
1354 <li><a href="#dnspromisesresolvehostname-rrtype"><code>resolver.resolve()</code></a></li>
1355 <li><a href="#dnspromisesresolve4hostname-options"><code>resolver.resolve4()</code></a></li>
1356 <li><a href="#dnspromisesresolve6hostname-options"><code>resolver.resolve6()</code></a></li>
1357 <li><a href="#dnspromisesresolveanyhostname"><code>resolver.resolveAny()</code></a></li>
1358 <li><a href="#dnspromisesresolvecaahostname"><code>resolver.resolveCaa()</code></a></li>
1359 <li><a href="#dnspromisesresolvecnamehostname"><code>resolver.resolveCname()</code></a></li>
1360 <li><a href="#dnspromisesresolvemxhostname"><code>resolver.resolveMx()</code></a></li>
1361 <li><a href="#dnspromisesresolvenaptrhostname"><code>resolver.resolveNaptr()</code></a></li>
1362 <li><a href="#dnspromisesresolvenshostname"><code>resolver.resolveNs()</code></a></li>
1363 <li><a href="#dnspromisesresolveptrhostname"><code>resolver.resolvePtr()</code></a></li>
1364 <li><a href="#dnspromisesresolvesoahostname"><code>resolver.resolveSoa()</code></a></li>
1365 <li><a href="#dnspromisesresolvesrvhostname"><code>resolver.resolveSrv()</code></a></li>
1366 <li><a href="#dnspromisesresolvetxthostname"><code>resolver.resolveTxt()</code></a></li>
1367 <li><a href="#dnspromisesreverseip"><code>resolver.reverse()</code></a></li>
1368 <li><a href="#dnspromisessetserversservers"><code>resolver.setServers()</code></a></li>
1370 <h4><code>resolver.cancel()</code><span><a class="mark" href="#resolvercancel_1" id="resolvercancel…
1375 promises will be rejected with an error with the code <code>ECANCELLED</code>.</p>
1376 <h4><code>dnsPromises.getServers()</code><span><a class="mark" href="#dnspromisesgetservers" id="dn…
1381 <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Strin…
1383 …rings, formatted according to <a href="https://tools.ietf.org/html/rfc5952#section-6">RFC 5952</a>,
1386 <!-- eslint-disable semi-->
1387 <pre><code class="language-js">[
1388 <span class="hljs-string">'4.4.4.4'</span>,
1389 <span class="hljs-string">'2001:4860:4860::8888'</span>,
1390 <span class="hljs-string">'4.4.4.4:1053'</span>,
1391 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
1392 ]</code> <button class="copy-button">copy</button></pre>
1393 …code>dnsPromises.lookup(hostname[, options])</code><span><a class="mark" href="#dnspromiseslookuph…
1398 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1399 …code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
1401 …code>family</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
1402 <code>0</code> indicates that IPv4 and IPv6 addresses are both returned. <strong>Default:</strong>
1403 <code>0</code>.</li>
1404 …code>hints</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
1405 flags may be passed by bitwise <code>OR</code>ing their values.</li>
1406 …code>all</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B…
1407 an array. Otherwise, returns a single address. <strong>Default:</strong> <code>false</code>.</li>
1408 …code>verbatim</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
1409 IPv6 addresses in the order the DNS resolver returned them. When <code>false</code>,
1411 <strong>Default:</strong> currently <code>false</code> (addresses are reordered) but this is
1413 configurable using <a href="#dnssetdefaultresultorderorder"><code>dns.setDefaultResultOrder()</code…
1414 <a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>. New code should use…
1418 <p>Resolves a host name (e.g. <code>'nodejs.org'</code>) into the first found A (IPv4) or
1419 AAAA (IPv6) record. All <code>option</code> properties are optional. If <code>options</code> is an
1420 integer, then it must be <code>4</code> or <code>6</code> – if <code>options</code> is not provided…
1422 <p>With the <code>all</code> option set to <code>true</code>, the <code>Promise</code> is resolved …
1423 being an array of objects with the properties <code>address</code> and <code>family</code>.</p>
1424 …rror, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</…
1425 is the error code.
1426 Keep in mind that <code>err.code</code> will be set to <code>'ENOTFOUND'</code> not only when
1429 <p><a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a> does not nece…
1433 take some time to consult the <a href="#implementation-considerations">Implementation consideration…
1434 using <code>dnsPromises.lookup()</code>.</p>
1436 <pre><code class="language-js"><span class="hljs-keyword">const</span> dns = <span class="hljs-buil…
1437 <span class="hljs-keyword">const</span> dnsPromises = dns.<span class="hljs-property">promises</spa…
1438 <span class="hljs-keyword">const</span> options = {
1439 <span class="hljs-attr">family</span>: <span class="hljs-number">6</span>,
1440 …<span class="hljs-attr">hints</span>: dns.<span class="hljs-property">ADDRCONFIG</span> | dns.<spa…
1443 …-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options).<span cla…
1444 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hlj…
1445 <span class="hljs-comment">// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6</span>
1448 <span class="hljs-comment">// When options.all is true, the result will be an Array.</span>
1449 options.<span class="hljs-property">all</span> = <span class="hljs-literal">true</span>;
1450 …-title function_">lookup</span>(<span class="hljs-string">'example.com'</span>, options).<span cla…
1451 …<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>…
1452 …<span class="hljs-comment">// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family"…
1453 });</code> <button class="copy-button">copy</button></pre>
1454 …code>dnsPromises.lookupService(address, port)</code><span><a class="mark" href="#dnspromiseslookup…
1459 <li><code>address</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_stru…
1460 <li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structu…
1462 <p>Resolves the given <code>address</code> and <code>port</code> into a host name and service using
1463 the operating system's underlying <code>getnameinfo</code> implementation.</p>
1464 <p>If <code>address</code> is not a valid IP address, a <code>TypeError</code> will be thrown.
1465 The <code>port</code> will be coerced to a number. If it is not a legal port, a <code>TypeError</co…
1467 …rror, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</…
1468 is the error code.</p>
1469 …code class="language-js"><span class="hljs-keyword">const</span> dnsPromises = <span class="hljs-b…
1470 …-title function_">lookupService</span>(<span class="hljs-string">'127.0.0.1'</span>, <span class="…
1471 …-variable language_">console</span>.<span class="hljs-title function_">log</span>(result.<span cla…
1472 <span class="hljs-comment">// Prints: localhost ssh</span>
1473 });</code> <button class="copy-button">copy</button></pre>
1474 …code>dnsPromises.resolve(hostname[, rrtype])</code><span><a class="mark" href="#dnspromisesresolve…
1479 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1480 …code>rrtype</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
1482 <p>Uses the DNS protocol to resolve a host name (e.g. <code>'nodejs.org'</code>) into an array
1483 of the resource records. When successful, the <code>Promise</code> is resolved with an
1485 based on <code>rrtype</code>:</p>
1569 …code>rrtype</code></th><th><code>records</code> contains</th><th>Result type</th><th>Shorthand met…
1570 …rror, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</…
1571 is one of the <a href="#error-codes">DNS error codes</a>.</p>
1572 …code>dnsPromises.resolve4(hostname[, options])</code><span><a class="mark" href="#dnspromisesresol…
1577 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1578 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
1580 …code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B…
1581 When <code>true</code>, the <code>Promise</code> is resolved with an array of
1582 <code>{ address: '1.2.3.4', ttl: 60 }</code> objects rather than an array of strings,
1587 <p>Uses the DNS protocol to resolve IPv4 addresses (<code>A</code> records) for the
1588 <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv4
1589 addresses (e.g. <code>['74.125.79.104', '74.125.79.105', '74.125.79.106']</code>).</p>
1590 …code>dnsPromises.resolve6(hostname[, options])</code><span><a class="mark" href="#dnspromisesresol…
1595 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1596 <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference…
1598 …code>ttl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#B…
1599 When <code>true</code>, the <code>Promise</code> is resolved with an array of
1600 <code>{ address: '0:1:2:3:4:5:6:7', ttl: 60 }</code> objects rather than an array of
1605 <p>Uses the DNS protocol to resolve IPv6 addresses (<code>AAAA</code> records) for the
1606 <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of IPv6
1608 …code>dnsPromises.resolveAny(hostname)</code><span><a class="mark" href="#dnspromisesresolveanyhost…
1613 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1615 <p>Uses the DNS protocol to resolve all records (also known as <code>ANY</code> or <code>*</code> q…
1616 On success, the <code>Promise</code> is resolved with an array containing various types of
1617 records. Each object has a property <code>type</code> that indicates the type of the
1618 current record. And depending on the <code>type</code>, additional properties will be
1669 …code>'A'</code></td><td><code>address</code>/<code>ttl</code></td></tr><tr><td><code>'AAAA'</code>…
1671 <!-- eslint-disable semi -->
1672 …code class="language-js">[ { <span class="hljs-attr">type</span>: <span class="hljs-string">'A'</s…
1673 …<span class="hljs-attr">type</span>: <span class="hljs-string">'CNAME'</span>, <span class="hljs-a…
1674 …-attr">type</span>: <span class="hljs-string">'MX'</span>, <span class="hljs-attr">exchange</span>…
1675 …{ <span class="hljs-attr">type</span>: <span class="hljs-string">'NS'</span>, <span class="hljs-at…
1676 …span class="hljs-attr">type</span>: <span class="hljs-string">'TXT'</span>, <span class="hljs-attr…
1677 { <span class="hljs-attr">type</span>: <span class="hljs-string">'SOA'</span>,
1678 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns1.example.com'</span>,
1679 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'admin.example.com'</span>,
1680 <span class="hljs-attr">serial</span>: <span class="hljs-number">156696742</span>,
1681 <span class="hljs-attr">refresh</span>: <span class="hljs-number">900</span>,
1682 <span class="hljs-attr">retry</span>: <span class="hljs-number">900</span>,
1683 <span class="hljs-attr">expire</span>: <span class="hljs-number">1800</span>,
1684 …<span class="hljs-attr">minttl</span>: <span class="hljs-number">60</span> } ]</code> <button clas…
1685 …code>dnsPromises.resolveCaa(hostname)</code><span><a class="mark" href="#dnspromisesresolvecaahost…
1690 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1692 <p>Uses the DNS protocol to resolve <code>CAA</code> records for the <code>hostname</code>. On succ…
1693 the <code>Promise</code> is resolved with an array of objects containing available
1694 certification authority authorization records available for the <code>hostname</code>
1695 (e.g. <code>[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com…
1696 …code>dnsPromises.resolveCname(hostname)</code><span><a class="mark" href="#dnspromisesresolvecname…
1701 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1703 <p>Uses the DNS protocol to resolve <code>CNAME</code> records for the <code>hostname</code>. On su…
1704 the <code>Promise</code> is resolved with an array of canonical name records available for
1705 the <code>hostname</code> (e.g. <code>['bar.example.com']</code>).</p>
1706 …code>dnsPromises.resolveMx(hostname)</code><span><a class="mark" href="#dnspromisesresolvemxhostna…
1711 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1713 <p>Uses the DNS protocol to resolve mail exchange records (<code>MX</code> records) for the
1714 <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects
1715 containing both a <code>priority</code> and <code>exchange</code> property (e.g.
1716 <code>[{priority: 10, exchange: 'mx.example.com'}, ...]</code>).</p>
1717 …code>dnsPromises.resolveNaptr(hostname)</code><span><a class="mark" href="#dnspromisesresolvenaptr…
1722 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1724 <p>Uses the DNS protocol to resolve regular expression-based records (<code>NAPTR</code>
1725 records) for the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an ar…
1728 <li><code>flags</code></li>
1729 <li><code>service</code></li>
1730 <li><code>regexp</code></li>
1731 <li><code>replacement</code></li>
1732 <li><code>order</code></li>
1733 <li><code>preference</code></li>
1735 <!-- eslint-skip -->
1736 <pre><code class="language-js">{
1737 <span class="hljs-attr">flags</span>: <span class="hljs-string">'s'</span>,
1738 <span class="hljs-attr">service</span>: <span class="hljs-string">'SIP+D2U'</span>,
1739 <span class="hljs-attr">regexp</span>: <span class="hljs-string">''</span>,
1740 …<span class="hljs-attr">replacement</span>: <span class="hljs-string">'_sip._udp.example.com'</spa…
1741 <span class="hljs-attr">order</span>: <span class="hljs-number">30</span>,
1742 <span class="hljs-attr">preference</span>: <span class="hljs-number">100</span>
1743 }</code> <button class="copy-button">copy</button></pre>
1744 …code>dnsPromises.resolveNs(hostname)</code><span><a class="mark" href="#dnspromisesresolvenshostna…
1749 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1751 <p>Uses the DNS protocol to resolve name server records (<code>NS</code> records) for the
1752 <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of name server
1753 records available for <code>hostname</code> (e.g.
1754 <code>['ns1.example.com', 'ns2.example.com']</code>).</p>
1755 …code>dnsPromises.resolvePtr(hostname)</code><span><a class="mark" href="#dnspromisesresolveptrhost…
1760 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1762 <p>Uses the DNS protocol to resolve pointer records (<code>PTR</code> records) for the
1763 <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of strings
1765 …code>dnsPromises.resolveSoa(hostname)</code><span><a class="mark" href="#dnspromisesresolvesoahost…
1770 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1772 <p>Uses the DNS protocol to resolve a start of authority record (<code>SOA</code> record) for
1773 the <code>hostname</code>. On success, the <code>Promise</code> is resolved with an object with the
1776 <li><code>nsname</code></li>
1777 <li><code>hostmaster</code></li>
1778 <li><code>serial</code></li>
1779 <li><code>refresh</code></li>
1780 <li><code>retry</code></li>
1781 <li><code>expire</code></li>
1782 <li><code>minttl</code></li>
1784 <!-- eslint-skip -->
1785 <pre><code class="language-js">{
1786 <span class="hljs-attr">nsname</span>: <span class="hljs-string">'ns.example.com'</span>,
1787 <span class="hljs-attr">hostmaster</span>: <span class="hljs-string">'root.example.com'</span>,
1788 <span class="hljs-attr">serial</span>: <span class="hljs-number">2013101809</span>,
1789 <span class="hljs-attr">refresh</span>: <span class="hljs-number">10000</span>,
1790 <span class="hljs-attr">retry</span>: <span class="hljs-number">2400</span>,
1791 <span class="hljs-attr">expire</span>: <span class="hljs-number">604800</span>,
1792 <span class="hljs-attr">minttl</span>: <span class="hljs-number">3600</span>
1793 }</code> <button class="copy-button">copy</button></pre>
1794 …code>dnsPromises.resolveSrv(hostname)</code><span><a class="mark" href="#dnspromisesresolvesrvhost…
1799 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1801 <p>Uses the DNS protocol to resolve service records (<code>SRV</code> records) for the
1802 <code>hostname</code>. On success, the <code>Promise</code> is resolved with an array of objects wi…
1805 <li><code>priority</code></li>
1806 <li><code>weight</code></li>
1807 <li><code>port</code></li>
1808 <li><code>name</code></li>
1810 <!-- eslint-skip -->
1811 <pre><code class="language-js">{
1812 <span class="hljs-attr">priority</span>: <span class="hljs-number">10</span>,
1813 <span class="hljs-attr">weight</span>: <span class="hljs-number">5</span>,
1814 <span class="hljs-attr">port</span>: <span class="hljs-number">21223</span>,
1815 <span class="hljs-attr">name</span>: <span class="hljs-string">'service.example.com'</span>
1816 }</code> <button class="copy-button">copy</button></pre>
1817 …code>dnsPromises.resolveTxt(hostname)</code><span><a class="mark" href="#dnspromisesresolvetxthost…
1822 <li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_str…
1824 <p>Uses the DNS protocol to resolve text queries (<code>TXT</code> records) for the
1825 <code>hostname</code>. On success, the <code>Promise</code> is resolved with a two-dimensional array
1826 of the text records available for <code>hostname</code> (e.g.
1827 <code>[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]</code>). Each sub-array contains TXT chunks of
1830 <h4><code>dnsPromises.reverse(ip)</code><span><a class="mark" href="#dnspromisesreverseip" id="dnsp…
1835 <li><code>ip</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structure…
1839 …rror, the <code>Promise</code> is rejected with an <a href="errors.html#class-error"><code>Error</…
1840 is one of the <a href="#error-codes">DNS error codes</a>.</p>
1841 …code>dnsPromises.setDefaultResultOrder(order)</code><span><a class="mark" href="#dnspromisessetdef…
1847 <td><p>Changed default value to <code>verbatim</code>.</p></td></tr>
1854 …code>order</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures…
1856 <p>Set the default value of <code>verbatim</code> in <a href="#dnslookuphostname-options-callback">…
1857 <a href="#dnspromiseslookuphostname-options"><code>dnsPromises.lookup()</code></a>. The value could…
1859 <li><code>ipv4first</code>: sets default <code>verbatim</code> <code>false</code>.</li>
1860 <li><code>verbatim</code>: sets default <code>verbatim</code> <code>true</code>.</li>
1862 …The default is <code>verbatim</code> and <a href="#dnspromisessetdefaultresultorderorder"><code>dn…
1863 higher priority than <a href="cli.html#--dns-result-orderorder"><code>--dns-result-order</code></a>…
1864 <a href="#dnspromisessetdefaultresultorderorder"><code>dnsPromises.setDefaultResultOrder()</code></…
1866 …code>dnsPromises.getDefaultResultOrder()</code><span><a class="mark" href="#dnspromisesgetdefaultr…
1870 <p>Get the value of <code>dnsOrder</code>.</p>
1871 …code>dnsPromises.setServers(servers)</code><span><a class="mark" href="#dnspromisessetserversserve…
1876 …code>servers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structur…
1879 resolution. The <code>servers</code> argument is an array of <a href="https://tools.ietf.org/html/r…
1881 <pre><code class="language-js">dnsPromises.<span class="hljs-title function_">setServers</span>([
1882 <span class="hljs-string">'4.4.4.4'</span>,
1883 <span class="hljs-string">'[2001:4860:4860::8888]'</span>,
1884 <span class="hljs-string">'4.4.4.4:1053'</span>,
1885 <span class="hljs-string">'[2001:4860:4860::8888]:1053'</span>,
1886 ]);</code> <button class="copy-button">copy</button></pre>
1888 <p>The <code>dnsPromises.setServers()</code> method must not be called while a DNS query is in
1891 <a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolve.conf</a>.
1893 <code>NOTFOUND</code> error, the <code>resolve()</code> method will <em>not</em> attempt to resolve…
1896 …tion><h3>Error codes<span><a class="mark" href="#error-codes" id="error-codes">#</a></span><a aria…
1899 <li><code>dns.NODATA</code>: DNS server returned an answer with no data.</li>
1900 <li><code>dns.FORMERR</code>: DNS server claims query was misformatted.</li>
1901 <li><code>dns.SERVFAIL</code>: DNS server returned general failure.</li>
1902 <li><code>dns.NOTFOUND</code>: Domain name not found.</li>
1903 <li><code>dns.NOTIMP</code>: DNS server does not implement the requested operation.</li>
1904 <li><code>dns.REFUSED</code>: DNS server refused query.</li>
1905 <li><code>dns.BADQUERY</code>: Misformatted DNS query.</li>
1906 <li><code>dns.BADNAME</code>: Misformatted host name.</li>
1907 <li><code>dns.BADFAMILY</code>: Unsupported address family.</li>
1908 <li><code>dns.BADRESP</code>: Misformatted DNS reply.</li>
1909 <li><code>dns.CONNREFUSED</code>: Could not contact DNS servers.</li>
1910 <li><code>dns.TIMEOUT</code>: Timeout while contacting DNS servers.</li>
1911 <li><code>dns.EOF</code>: End of file.</li>
1912 <li><code>dns.FILE</code>: Error reading file.</li>
1913 <li><code>dns.NOMEM</code>: Out of memory.</li>
1914 <li><code>dns.DESTRUCTION</code>: Channel is being destroyed.</li>
1915 <li><code>dns.BADSTR</code>: Misformatted string.</li>
1916 <li><code>dns.BADFLAGS</code>: Illegal flags specified.</li>
1917 <li><code>dns.NONAME</code>: Given host name is not numeric.</li>
1918 <li><code>dns.BADHINTS</code>: Illegal hints flags specified.</li>
1919 <li><code>dns.NOTINITIALIZED</code>: c-ares library initialization not yet performed.</li>
1920 <li><code>dns.LOADIPHLPAPI</code>: Error loading <code>iphlpapi.dll</code>.</li>
1921 <li><code>dns.ADDRGETNETWORKPARAMS</code>: Could not find <code>GetNetworkParams</code> function.</…
1922 <li><code>dns.CANCELLED</code>: DNS query cancelled.</li>
1924 <p>The <code>dnsPromises</code> API also exports the above error codes, e.g., <code>dnsPromises.NOD…
1925 …an><a class="mark" href="#implementation-considerations" id="implementation-considerations">#</a><…
1926 …href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> and the various <code>dns…
1931 <h4><code>dns.lookup()</code><span><a class="mark" href="#dnslookup" id="dnslookup">#</a></span><a …
1932 <p>Under the hood, <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code></a> uses…
1933 …her programs. For instance, <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code…
1934 resolve a given name the same way as the <code>ping</code> command. On most POSIX-like
1935 …ystems, the behavior of the <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code…
1936 …-pages/man5/nsswitch.conf.5.html"><code>nsswitch.conf(5)</code></a> and/or <a href="http://man7.or…
1939 <p>Though the call to <code>dns.lookup()</code> will be asynchronous from JavaScript's
1940 …nous call to <a href="http://man7.org/linux/man-pages/man3/getaddrinfo.3.html"><code>getaddrinfo(3…
1942 …applications, see the <a href="cli.html#uv_threadpool_sizesize"><code>UV_THREADPOOL_SIZE</code></a>
1944 <p>Various networking APIs will call <code>dns.lookup()</code> internally to resolve
1946 using <code>dns.resolve()</code> and using the address instead of a host name. Also, some
1947 …tions-connectlistener"><code>socket.connect()</code></a> and <a href="dgram.html#dgramcreatesocket…
1948 allow the default resolver, <code>dns.lookup()</code>, to be replaced.</p>
1949 …code>dns.resolve()</code>, <code>dns.resolve*()</code>, and <code>dns.reverse()</code><span><a cla…
1950 …nted quite differently than <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code…
1951 do not use <a href="http://man7.org/linux/man-pages/man3/getaddrinfo.3.html"><code>getaddrinfo(3)</…
1955 … on libuv's threadpool that <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code…
1956 …of configuration files that <a href="#dnslookuphostname-options-callback"><code>dns.lookup()</code…
1957 uses. For instance, they do not use the configuration from <code>/etc/hosts</code>.</p></section>
1958 <!-- API END -->