@@ -15,9 +15,10 @@ For example, looking up `nodejs.org`.
15
15
``` js
16
16
const dns = require (' dns' );
17
17
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 );
20
20
});
21
+ // address: "192.0.43.8" family: IPv4
21
22
```
22
23
23
24
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
115
116
time to consult the [ Implementation considerations section] [ ] before using
116
117
` dns.lookup() ` .
117
118
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
+
118
138
### Supported getaddrinfo flags
119
139
120
140
The following flags can be passed as hints to [ ` dns.lookup() ` ] [ ] .
0 commit comments