![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – dns.getServers() Method
The dns.getServers() method returns an array of IP address strings. The address will be formatted as per the RFC 5952 standard, that are configured for DNS resolution. The string will also include the port section if a custom port is used.
Syntax
dns.getServers()
Parameters
Since it returns the list of the servers, it does not need any parameters.
Example 1
Create a file "getServers.js" and copy the following code snippet. After creating the file, use the command "node getServers.js" to run this code.
// dns.getServers() Node js Example // Importing the dns module const dns = require('dns'); // Reading the IP related info // for the current host console.log(dns.getServers());
Output
[ '213.133.98.98', '213.133.100.100', '213.133.99.99' ]
Example 2
// dns.getServers() Node js Example // Importing the dns module const dns = require('dns'); // Reading the IP related info // for all hosts allServers = dns.getServers(); // Iterating over all the IP's and printing them allServers.forEach(element => { console.log(element); });
Output
213.133.98.98 213.133.100.100 213.133.99.99
Advertisements