Skip to content

Commit 6c9bc3c

Browse files
Trotttargos
authored andcommitted
doc: improve dns introduction
The introductory paragraphs for the `dns` module do not explain what the module is for. Add a short (two brief sentences) explanation. It also emphasizes that functions in the dns module are divided into two categories, but that there is only one function in one of the categories, making the whole categories thing a bit odd to emphasize. Keep the material about the distinctions without discussing categories. There are other incidental revisions (changing an example IP to `example.org` and so on). PR-URL: #31090 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 671a5b7 commit 6c9bc3c

File tree

1 file changed

+39
-47
lines changed

1 file changed

+39
-47
lines changed

doc/api/dns.md

+39-47
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,51 @@
44

55
> Stability: 2 - Stable
66
7-
The `dns` module contains functions belonging to two different categories:
7+
The `dns` module enables name resolution. For example, use it to look up IP
8+
addresses of host names.
89

9-
1. Functions that use the underlying operating system facilities to perform
10-
name resolution, and that do not necessarily perform any network
11-
communication.
12-
This category contains only one function: [`dns.lookup()`][]. **Developers
13-
looking to perform name resolution in the same way that other applications
14-
on the same operating system behave should use [`dns.lookup()`][].**
10+
Although named for the Domain Name System (DNS), it does not always use the DNS
11+
protocol for lookups. [`dns.lookup()`][] uses the operating system facilities to
12+
perform name resolution. It may not need to perform any network communication.
13+
Developers looking to perform name resolution in the same way that other
14+
applications on the same operating system behave should use [`dns.lookup()`][].
1515

16-
For example, looking up `iana.org`.
16+
```js
17+
const dns = require('dns');
1718

18-
```js
19-
const dns = require('dns');
19+
dns.lookup('example.org', (err, address, family) => {
20+
console.log('address: %j family: IPv%s', address, family);
21+
});
22+
// address: "93.184.216.34" family: IPv4
23+
```
2024

21-
dns.lookup('iana.org', (err, address, family) => {
22-
console.log('address: %j family: IPv%s', address, family);
23-
});
24-
// address: "192.0.43.8" family: IPv4
25-
```
26-
27-
2. Functions that connect to an actual DNS server to perform name resolution,
28-
and that _always_ use the network to perform DNS queries. This category
29-
contains all functions in the `dns` module _except_ [`dns.lookup()`][].
30-
These functions do not use the same set of configuration files used by
31-
[`dns.lookup()`][] (e.g. `/etc/hosts`). These functions should be used by
32-
developers who do not want to use the underlying operating system's
33-
facilities for name resolution, and instead want to _always_ perform DNS
34-
queries.
35-
36-
Below is an example that resolves `'archive.org'` then reverse resolves the
37-
IP addresses that are returned.
38-
39-
```js
40-
const dns = require('dns');
41-
42-
dns.resolve4('archive.org', (err, addresses) => {
43-
if (err) throw err;
44-
45-
console.log(`addresses: ${JSON.stringify(addresses)}`);
46-
47-
addresses.forEach((a) => {
48-
dns.reverse(a, (err, hostnames) => {
49-
if (err) {
50-
throw err;
51-
}
52-
console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
53-
});
54-
});
25+
All other functions in the `dns` module connect to an actual DNS server to
26+
perform name resolution. They will always use the network to perform DNS
27+
queries. These functions do not use the same set of configuration files used by
28+
[`dns.lookup()`][] (e.g. `/etc/hosts`). These functions should be used by
29+
developers who do not want to use the underlying operating system's
30+
facilities for name resolution, and instead want to always perform DNS queries.
31+
32+
```js
33+
const dns = require('dns');
34+
35+
dns.resolve4('archive.org', (err, addresses) => {
36+
if (err) throw err;
37+
38+
console.log(`addresses: ${JSON.stringify(addresses)}`);
39+
40+
addresses.forEach((a) => {
41+
dns.reverse(a, (err, hostnames) => {
42+
if (err) {
43+
throw err;
44+
}
45+
console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
5546
});
56-
```
47+
});
48+
});
49+
```
5750

58-
There are subtle consequences in choosing one over the other, please consult
59-
the [Implementation considerations section][] for more information.
51+
See the [Implementation considerations section][] for more information.
6052

6153
## Class: `dns.Resolver`
6254
<!-- YAML

0 commit comments

Comments
 (0)