Node.js dnsPromises.reverse() Method
Last Updated :
13 Oct, 2021
The dnsPromises.reverse() method is an inbuilt application programming interface of the promises object of dns module which is used to resolve hostname for the specified IP address using reverse DNS query.
Syntax:
dnsPromises.reverse(ip_address)
Parameters: This method has one parameter as mentioned above and described below:
- ip_address: This parameter specifies an IP address (IPv4 or IPv6) to be resolved.
Return Value: This method returns error, hostname.
Below examples illustrate the use of dnsPromises.reverse() method in Node.js:
Example 1:
const dns = require( 'dns' );
const dnsPromises = dns.promises;
dnsPromises.reverse( '31.13.66.35' ).then((res) => {
console.log(res);
});
|
Output:
[ 'edge-star-mini-shv-01-iad3.facebook.com' ]
Example 2:
const dns = require( 'dns' );
const dnsPromises = dns.promises;
(async function () {
const records = await dnsPromises.reverse(
'34.218.62.116' );
console.log( "from async: " );
console.log(records);
})();
|
Output:
from async:
[ 'ec2-34-218-62-116.us-west-2.compute.amazonaws.com' ]
Note: The above program will compile and run by using the node index.js
command.
Reference: https://nodejs.org/api/dns.html#dns_dnspromises_reverse_ip
Share your thoughts in the comments
Please Login to comment...