Skip to content

Commit 5b379e0

Browse files
silverwindMylesBorins
authored andcommitted
doc: clarify the callback arguments of dns.resolve
PR-URL: #9532 Backport-PR-URL: #13073 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent f236dcb commit 5b379e0

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

doc/api/dns.md

+35-25
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,32 @@ dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
169169
added: v0.1.27
170170
-->
171171

172-
Uses the DNS protocol to resolve a hostname (e.g. `'nodejs.org'`) into an
173-
array of the record types specified by `rrtype`.
174-
175-
Valid values for `rrtype` are:
176-
177-
* `'A'` - IPV4 addresses, default
178-
* `'AAAA'` - IPV6 addresses
179-
* `'MX'` - mail exchange records
180-
* `'TXT'` - text records
181-
* `'SRV'` - SRV records
182-
* `'PTR'` - PTR records
183-
* `'NS'` - name server records
184-
* `'CNAME'` - canonical name records
185-
* `'SOA'` - start of authority record
186-
* `'NAPTR'` - name authority pointer record
187-
188-
The `callback` function has arguments `(err, addresses)`. When successful,
189-
`addresses` will be an array, except when resolving an SOA record which returns
190-
an object structured in the same manner as one returned by the
191-
[`dns.resolveSoa()`][] method. The type of each item in `addresses` is
192-
determined by the record type, and described in the documentation for the
193-
corresponding lookup methods.
194-
195-
On error, `err` is an [`Error`][] object, where `err.code` is
196-
one of the error codes listed [here](#dns_error_codes).
172+
- `hostname` {string} Hostname to resolve.
173+
- `rrtype` {string} Resource record type. Default: `'A'`.
174+
- `callback` {Function}
175+
- `err` {Error}
176+
- `records` {string[] | Object[] | string[][] | Object}
177+
178+
Uses the DNS protocol to resolve a hostname (e.g. `'nodejs.org'`) into an array
179+
of the resource records. The `callback` function has arguments
180+
`(err, records)`. When successful, `records` will be an array of resource
181+
records. The type and structure of individual results varies based on `rrtype`:
182+
183+
| `rrtype` | `records` contains | Result type | Shorthand method |
184+
|-----------|--------------------------------|-------------|--------------------------|
185+
| `'A'` | IPv4 addresses (default) | {string} | [`dns.resolve4()`][] |
186+
| `'AAAA'` | IPv6 addresses | {string} | [`dns.resolve6()`][] |
187+
| `'CNAME'` | canonical name records | {string} | [`dns.resolveCname()`][] |
188+
| `'MX'` | mail exchange records | {Object} | [`dns.resolveMx()`][] |
189+
| `'NAPTR'` | name authority pointer records | {Object} | [`dns.resolveNaptr()`][] |
190+
| `'NS'` | name server records | {string} | [`dns.resolveNs()`][] |
191+
| `'PTR'` | pointer records | {string} | [`dns.resolvePtr()`][] |
192+
| `'SOA'` | start of authority records | {Object} | [`dns.resolveSoa()`][] |
193+
| `'SRV'` | service records | {Object} | [`dns.resolveSrv()`][] |
194+
| `'TXT'` | text records | {string} | [`dns.resolveTxt()`][] |
195+
196+
On error, `err` is an [`Error`][] object, where `err.code` is one of the
197+
[DNS error codes](#dns_error_codes).
197198

198199
## dns.resolve4(hostname[, options], callback)
199200
<!-- YAML
@@ -463,7 +464,16 @@ uses. For instance, _they do not use the configuration from `/etc/hosts`_.
463464

464465
[DNS error codes]: #dns_error_codes
465466
[`dns.lookup()`]: #dns_dns_lookup_hostname_options_callback
467+
[`dns.resolve4()`]: #dns_dns_resolve4_hostname_options_callback
468+
[`dns.resolve6()`]: #dns_dns_resolve6_hostname_options_callback
469+
[`dns.resolveCname()`]: #dns_dns_resolvecname_hostname_callback
470+
[`dns.resolveMx()`]: #dns_dns_resolvemx_hostname_callback
471+
[`dns.resolveNaptr()`]: #dns_dns_resolvenaptr_hostname_callback
472+
[`dns.resolveNs()`]: #dns_dns_resolvens_hostname_callback
473+
[`dns.resolvePtr()`]: #dns_dns_resolveptr_hostname_callback
466474
[`dns.resolveSoa()`]: #dns_dns_resolvesoa_hostname_callback
475+
[`dns.resolveSrv()`]: #dns_dns_resolvesrv_hostname_callback
476+
[`dns.resolveTxt()`]: #dns_dns_resolvetxt_hostname_callback
467477
[`Error`]: errors.html#errors_class_error
468478
[Implementation considerations section]: #dns_implementation_considerations
469479
[supported `getaddrinfo` flags]: #dns_supported_getaddrinfo_flags

0 commit comments

Comments
 (0)