Skip to content

Commit c3c874f

Browse files
sam-githubitaloacasas
authored andcommitted
doc: dns examples implied string args were arrays
Fix: #11334 PR-URL: #11350 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent aef67cf commit c3c874f

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

doc/api/dns.md

+23-11
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ For example, looking up `iana.org`.
1515
```js
1616
const dns = require('dns');
1717

18-
dns.lookup('iana.org', (err, addresses, family) => {
19-
console.log('addresses:', addresses);
18+
dns.lookup('iana.org', (err, address, family) => {
19+
console.log('address: %j family: IPv%s', address, family);
2020
});
21+
// address: "192.0.43.8" family: IPv4
2122
```
2223

2324
2) Functions that connect to an actual DNS server to perform name resolution,
@@ -84,15 +85,7 @@ Alternatively, `options` can be an object containing these properties:
8485
* `all`: {Boolean} - When `true`, the callback returns all resolved addresses
8586
in an array, otherwise returns a single address. Defaults to `false`.
8687

87-
All properties are optional. An example usage of options is shown below.
88-
89-
```js
90-
{
91-
family: 4,
92-
hints: dns.ADDRCONFIG | dns.V4MAPPED,
93-
all: false
94-
}
95-
```
88+
All properties are optional.
9689

9790
The `callback` function has arguments `(err, address, family)`. `address` is a
9891
string representation of an IPv4 or IPv6 address. `family` is either the
@@ -115,6 +108,25 @@ important consequences on the behavior of any Node.js program. Please take some
115108
time to consult the [Implementation considerations section][] before using
116109
`dns.lookup()`.
117110

111+
Example usage:
112+
113+
```js
114+
const dns = require('dns');
115+
const options = {
116+
family: 6,
117+
hints: dns.ADDRCONFIG | dns.V4MAPPED,
118+
};
119+
dns.lookup('example.com', options, (err, address, family) =>
120+
console.log('address: %j family: IPv%s', address, family));
121+
// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
122+
123+
// When options.all is true, the result will be an Array.
124+
options.all = true;
125+
dns.lookup('example.com', options, (err, addresses) =>
126+
console.log('addresses: %j', addresses));
127+
// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
128+
```
129+
118130
### Supported getaddrinfo flags
119131

120132
The following flags can be passed as hints to [`dns.lookup()`][].

0 commit comments

Comments
 (0)