![]() |
VOOZH | about |
The
dnsPromises.lookup() method
is an inbuilt application programming interface of the promises object of dns module which is used to resolve IP addresses of the specified hostname for given parameters into the first found A (IPv4) or AAAA (IPv6) record.
Syntax:
dnsPromises.lookup( hostname, options )Parameters:
This method has two parameters as mentioned above and described below:
Return Value:
This method returns error, family of IP addresses and IP addresses. Below examples illustrate the use of dnsPromises.lookup() method in Node.js:
Example 1:
Output:
family: IPv6 address: "fd00:0:14:13::22da:3e74"
Example 2:
Output:
addresses: [{"address":"8.8.8.8", "family":4},
{"address":"fd00:0:14:13::22da:3e74", "family":6}]
Example 3:
Output:
from async:
[ { address: '8.8.8.8', family: 4 },
{ address: 'fd00:0:14:13::22da:3e74', family: 6 } ]
Note:
The above program will compile and run by using the
node index.js
command.
Reference:
https://nodejs.org/api/dns.html#dns_dnspromises_lookup_hostname_options