Open In App

Node.js dnsPromises.resolveSoa() Method

The dnsPromises.resolveSoa() method is an inbuilt application programming interface of the promises object of dns module which is used to resolve SOA or start of authority records for the specified hostname using DNS protocol.

Syntax:



dnsPromises.resolveSoa( hostname )

Parameters: This method has one parameter as mentioned above and described below:

Return Value: This method returns error, addresses. The address parameter will contain nsname, hostmaster, serial, refresh, retry, expire and minttl properties.



Below examples illustrate the use of dnsPromises.resolveSoa() method in Node.js:

Example 1:




// Node.js program to demonstrate the   
// dnsPromises.resolveSoa() method
  
// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;
   
// Calling dnsPromises.resolveSoa() method 
dnsPromises.resolveSoa('google.com').then((res) => {
    console.log("for google : ");
    console.log(res);
});

Output:

for google :
{ nsname: 'ns1.google.com',
  hostmaster: 'dns-admin.google.com',
  serial: 290031082,
  refresh: 900,
  retry: 900,
  expire: 1800,
  minttl: 60
}

Example 2:




// Node.js program to demonstrate the   
// dnsPromises.resolveSoa() method
  
// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;
   
// Calling dnsPromises.resolveSoa() method 
// asynchronously 
(async function() {
      
    // Records from resolveSoa function
    const records = await dnsPromises.resolveSoa(
                    'geeksforgeeks.org');
      
    // Printing  records
    console.log("from async: ");
    console.log(records);   
})();

Output:

from async:
{ nsname: 'ns-869.awsdns-44.net',
  hostmaster: 'awsdns-hostmaster.amazon.com',
  serial: 1,
  refresh: 7200,
  retry: 900,
  expire: 1209600,
  minttl: 86400 
}

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/api/dns.html#dns_dnspromises_resolvesoa_hostname


Article Tags :