Node.js – dnsPromises.resolveSoa() Method

The dnsPromises.resolveSoa() method uses the DNS protocol to resolve the Start of Authority records (SOA Records) for the hostname. On success, the promise is resolved with the following properties

  • nsname

  • hostmaster

  • serial

  • refresh

  • retry

  • expire

  • minttl

Syntax

dnsPromises.resolveSoa( hostname )

Parameters

  • hostname - This parameter takes the input for the hostname to be resolved.

Example 1

Create a file with the name "resolveSoa.js" and copy the following code. After creating the file, use the command "node resolveSoa.js" to run this code as shown in the example below

// dns.resolveSoa() Demo Example

// Importing the dns module
const dns = require('dns');

const dnsPromises = dns.promises;

// Passing IP to find the hostname TXT records
dnsPromises.resolveSoa('tutorialspoint.com').then((response) => { 
   console.log("SOA Records: ", response);
})

Output

It will produce the following output −

C:\home\node>> node resolveSoa.js
SOA Records: { nsname: 'pdns13.domaincontrol.com',
   hostmaster: 'dns.jomax.net',
   serial: 2021051700,
   refresh: 28800,
   retry: 7200,
   expire: 604800,
   minttl: 600 }

Example 2

Let's take another example −

// dns.resolveSoa() Demo Example

// Importing the dns module
const dns = require('dns');

const dnsPromises = dns.promises;

// Setting ttl as true
const options={
   ttl:true,
};

// Calling dnsPromises.resolveSoa() method asynchronously
(async function() {
   const records = await dnsPromises.resolveSoa( 'google.com', options);

   // Printing records
   console.log("SOA Records: ", records);
})();

Output

It will produce the following output −

C:\home\node>> node resolveSoa.js
SOA Records: { nsname: 'ns1.google.com',
   hostmaster: 'dns-admin.google.com',
   serial: 379680302,
   refresh: 900,
   retry: 900,
   expire: 1800,
   minttl: 60 }
Updated on: 2021-11-24T06:57:12+05:30

135 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements