Node.js dns.resolveNs() Method (original) (raw)

Last Updated : 13 Oct, 2021

The dns.resolveNs() method is an inbuilt application programming interface of the dns module which is used to resolve NS or name server records for the specified hostname using DNS protocol.Syntax:

dns.resolveNs( hostname, callback )

Parameters: This method has two parameters as mentioned above and described below:

Return Value: This method returns error, addresses through callback function. These data are passed as parameters to the callback function. Below examples illustrate the use of dns.resolveNs() method in Node.js:Example 1:

javascript `

// Node.js program to demonstrate the
// dns.resolveNs() method

// Accessing dns module const dns = require('dns');

// Calling dns.resolveNs() method for hostname // geeksforgeeks.org and displaying them in // console as a callback dns.resolveNs('geeksforgeeks.org', (err, addresses) => console.log('NS records: %j', addresses));

`

Output:

NS records: [ "ns-1520.awsdns-62.org", "ns-1569.awsdns-04.co.uk", "ns-245.awsdns-30.com", "ns-869.awsdns-44.net" ]

Example 2:

javascript `

// Node.js program to demonstrate the
// dns.resolveNs() method

// Accessing dns module const dns = require('dns');

// Calling dns.resolveNs() method for // hostname google.com and displaying // them in console as a callback dns.resolveNs('google.com', (err, addresses) => console.log('NS records: %j', addresses));

`

Output:

NS records: [ "ns3.google.com", "ns2.google.com", "ns4.google.com", "ns1.google.com" ]

Note: The above program will compile and run by using the node index.js command.Reference: https://nodejs.org/api/dns.html#dns_dns_resolvens_hostname_callback