@@ -15,9 +15,10 @@ For example, looking up `nodejs.org`.
1515``` js
1616const 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
23242 ) 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
115116time 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
120140The following flags can be passed as hints to [ ` dns.lookup() ` ] [ ] .
0 commit comments