Open In App

Node.js dnsPromises.reverse() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Node.js program to demonstrate the   
// dnsPromises.reverse() method
  
// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;
   
// Calling dnsPromises.reverse() method 
dnsPromises.reverse('31.13.66.35').then((res) => {
    console.log(res);
});


Output:

[ 'edge-star-mini-shv-01-iad3.facebook.com' ]

Example 2:




// Node.js program to demonstrate the   
// dnsPromises.reverse() method
  
// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;
   
// Calling dnsPromises.reverse() method 
// asynchronously 
(async function() {
      
    // Records from reverse function
    const records = await dnsPromises.reverse(
                        '34.218.62.116');
      
    // Printing  records
    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



Last Updated : 13 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads