Node.js dns.resolveNs() Method
Last Updated :
13 Oct, 2021
Improve
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:
javascript
Output:
javascript
Output:
dns.resolveNs( hostname, callback )Parameters: This method has two parameters as mentioned above and described below:
- hostname: This parameter specifies a string which denotes the hostname to be resolved.
- callback: It specifies a function to be called after DNS resolution of the hostnames.
- error: It specifies error if generated.
- addresses: It is an array of string that signifies the returned name server records for the hostname.
// 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));
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:
// 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));
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