summaryrefslogtreecommitdiff
path: root/doc/api/dns.md
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2017-02-13 12:04:00 -0800
committerSam Roberts <vieuxtech@gmail.com>2017-02-16 09:40:32 -0800
commit642eec162d02f728473d5f6fae007e8696deecea (patch)
tree18574ec03d86c33586ce7f382d10e5216f78360c /doc/api/dns.md
parentadf1ed01463a66043ab8e912742f0f1765b45bfd (diff)
downloadandroid-node-v8-642eec162d02f728473d5f6fae007e8696deecea.tar.gz
android-node-v8-642eec162d02f728473d5f6fae007e8696deecea.tar.bz2
android-node-v8-642eec162d02f728473d5f6fae007e8696deecea.zip
doc: dns examples implied string args were arrays
Fix: https://github.com/nodejs/node/pull/11334 PR-URL: https://github.com/nodejs/node/pull/11350 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/dns.md')
-rw-r--r--doc/api/dns.md34
1 files changed, 23 insertions, 11 deletions
diff --git a/doc/api/dns.md b/doc/api/dns.md
index 40f830a3c8..f705d96246 100644
--- a/doc/api/dns.md
+++ b/doc/api/dns.md
@@ -15,9 +15,10 @@ For example, looking up `iana.org`.
```js
const dns = require('dns');
-dns.lookup('iana.org', (err, addresses, family) => {
- console.log('addresses:', addresses);
+dns.lookup('iana.org', (err, address, family) => {
+ console.log('address: %j family: IPv%s', address, family);
});
+// address: "192.0.43.8" family: IPv4
```
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:
* `all`: {Boolean} - When `true`, the callback returns all resolved addresses
in an array, otherwise returns a single address. Defaults to `false`.
-All properties are optional. An example usage of options is shown below.
-
-```js
-{
- family: 4,
- hints: dns.ADDRCONFIG | dns.V4MAPPED,
- all: false
-}
-```
+All properties are optional.
The `callback` function has arguments `(err, address, family)`. `address` is a
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
time to consult the [Implementation considerations section][] before using
`dns.lookup()`.
+Example usage:
+
+```js
+const dns = require('dns');
+const options = {
+ family: 6,
+ hints: dns.ADDRCONFIG | dns.V4MAPPED,
+};
+dns.lookup('example.com', options, (err, address, family) =>
+ console.log('address: %j family: IPv%s', address, family));
+// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
+
+// When options.all is true, the result will be an Array.
+options.all = true;
+dns.lookup('example.com', options, (err, addresses) =>
+ console.log('addresses: %j', addresses));
+// addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
+```
+
### Supported getaddrinfo flags
The following flags can be passed as hints to [`dns.lookup()`][].