@@ -15,9 +15,10 @@ For example, looking up `iana.org`.
1515``` js
1616const 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
23242 ) 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
9790The ` callback ` function has arguments ` (err, address, family) ` . ` address ` is a
9891string 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
115108time 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
120132The following flags can be passed as hints to [ ` dns.lookup() ` ] [ ] .
0 commit comments