VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-dns-getservers-method/

⇱ Node.js dns.getServers() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js dns.getServers() Method

Last Updated : 28 Apr, 2025

The dns.getServers() method is an inbuilt application programming interface of the dns module which is used to get IP addresses of the current server.
Syntax: 
 

dns.getServers()


Parameters: This method does not accept any parameters.
Return: This method returns an array of IP addresses in RFC 5952 format as configured in DNS resolution for the current host. A string will be attached as the port number if a custom port is being used.
Below examples illustrate the use of dns.getServers() method in Node.js:
Example 1: 
 

Output: 
 

[ '2402:3a80:1103:a055::34', '192.168.43.1' ]


Example 2: 
 

Output: 
 

72.28.94.156
2306:2470:3160::8888
72.28.94.156:1053
[2306:2470:3160::8888]:1053


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

Comment

Explore