Node.js dns.resolveNs() Method
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:
- 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.
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:
const dns = require( 'dns' );
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:
const dns = require( 'dns' );
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
Share your thoughts in the comments
Please Login to comment...