Skip to content

Commit 0c9ea4f

Browse files
sam-githubMylesBorins
authored andcommitted
doc: dns examples implied string args were arrays
Fix: #11334 PR-URL: #11350 Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d1a8588 commit 0c9ea4f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

doc/api/dns.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ For example, looking up `nodejs.org`.
1515
```js
1616
const dns = require('dns');
1717

18-
dns.lookup('nodejs.org', (err, addresses, family) => {
19-
console.log('addresses:', addresses);
18+
dns.lookup('nodejs.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,
@@ -115,6 +116,25 @@ important consequences on the behavior of any Node.js program. Please take some
115116
time to consult the [Implementation considerations section][] before using
116117
`dns.lookup()`.
117118

119+
Example usage:
120+
121+
```js
122+
const dns = require('dns');
123+
const options = {
124+
family: 6,
125+
hints: dns.ADDRCONFIG | dns.V4MAPPED,
126+
};
127+
dns.lookup('example.com', options, (err, address, family) =>
128+
console.log('address: %j family: IPv%s', address, family));
129+
// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
130+
131+
// When options.all is true, the result will be an Array.
132+
options.all = true;
133+
dns.lookup('example.com', options, (err, addresses) =>
134+
console.log('addresses: %j', addresses));
135+
// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
136+
```
137+
118138
### Supported getaddrinfo flags
119139

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

0 commit comments

Comments
 (0)