Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js DNS module

Node.js DNS module

Posted on September 25, 2025 By Rishabh saini No Comments on Node.js DNS module

Node.js DNS module

The Node.js DNS module provides powerful methods to interact with the Domain Name System (DNS). It allows developers to perform hostname lookups, resolve records, and even reverse IP addresses into hostnames.

Introduction to Applied AI:–Click Here

Below are some of the commonly used DNS functions in Node.js:

  • dns.getServers()
  • dns.setServers(servers)
  • dns.lookup(hostname[, options], callback)
  • dns.lookupService(address, port, callback)
  • dns.resolve(hostname[, rrtype], callback)
  • dns.resolve4(hostname, callback)
  • dns.resolve6(hostname, callback)
  • dns.resolveCname(hostname, callback)
  • dns.resolveMx(hostname, callback)
  • dns.resolveNs(hostname, callback)
  • dns.resolveSoa(hostname, callback)
  • dns.resolveSrv(hostname, callback)
  • dns.resolvePtr(hostname, callback)
  • dns.resolveTxt(hostname, callback)
  • dns.reverse(ip, callback)

Data Science Tutorial:-Click Here

Node.js DNS Example 1

Here’s a simple example using the dns.lookup() function:

Download New Real Time Projects :-Click here

File: dns_example1.js

const dns = require('dns');  

dns.lookup('www.updategadh.com', (err, addresses, family) => {  
  console.log('addresses:', addresses);  
  console.log('family:', family);  
});  

Run the file from the Node.js command line:

node dns_example1.js

Node.js DNS Example 2

Now, let’s use dns.resolve4() and dns.reverse() to resolve IPv4 addresses and then perform a reverse lookup:

Machine Learning Tutorial:–Click Here

File: dns_example2.js

const dns = require('dns');  

dns.resolve4('www.updategadh.com', (err, addresses) => {  
  if (err) throw err;  
  console.log(`addresses: ${JSON.stringify(addresses)}`);  

  addresses.forEach((a) => {  
    dns.reverse(a, (err, hostnames) => {  
      if (err) throw err;  
      console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);  
    });  
  });  
});  

Run the file:

node dns_example2.js

Node.js DNS Example 3

The dns.lookupService() method can be used to retrieve the hostname and service for a given IP address and port.

Complete Advance AI topics:- CLICK HERE

File: dns_example3.js

const dns = require('dns');  

dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {  
  if (err) throw err;  
  console.log(hostname, service);  
  // Example output: localhost ssh  
});  

Run the file:

node dns_example3.js

This article gave you a quick walkthrough of how the Node.js DNS module can be used for hostname lookups, resolving IP addresses, and reverse lookups.

Deep Learning Tutorial:– Click Here
Complete Python Course with Advance topics:-Click Here
SQL Tutorial :–Click Here


    node js dns lookup
    nodejs dns resolve example
    dns module in node js
    node dns server
    dns – npm
    node dns/promises
    npm node dns
    nodejs dns lookup cache
    node js dns server
    node js dns w3schools
    node js dns example

     

    Post Views: 275
    Node.js Tutorial Tags:ddos nodejs, deploy nodejs app, dns, dns lookup nodejs, dns module node, dns module nodejs, dns resolution nodejs, its always dns, node js dns, Node.js, nodejs, nodejs dns, nodejs dns lookup, nodejs dns module, nodejs dns module tutorial, nodejs essentials, nodejs example, nodejs get hostname, nodejs get hostname example, nodejs get server address, nodejs ip address lookup, nodejs resolve ip address, nodejs server lookup, nodejs tutorial, nodejs tutorial in hindi, resolve hostname to ip nodejs, what is nodejs

    Post navigation

    Previous Post: Library Management System using Python on Django Framework
    Next Post: Best Donor Prediction Web Application Using Machine Learning

    More Related Articles

    Node.js ZLIB Node.js ZLIB Node.js Tutorial
    Node.js Timer Node.js Timer Node.js Tutorial
    Node.js vs Java Node.js vs Java – Python Project with Source Code Node.js Tutorial

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    You may also like

    1. Node.js Command Line Options
    2. Node.js Child Process
    3. Node.js Assertion Testing
    4. Node.js Events
    5. Node.js MySQL Delete Records
    6. Node.js Create Connection with MongoDB

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. Flipkart Clone using PHP And MYSQL Free Source Code
    5. News Portal Project in PHP and MySql Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Blog Site In PHP And MYSQL With Source Code || Best Project
    9. Online Bike Rental Management System Using PHP and MySQL
    10. E learning Website in php with Free source code
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • AI-Powered Online Examination System with Face Detection Using PHP & MySQL
    • Real-Time Medical Queue & Appointment System with Django
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL

    Most Viewed Posts

    • Top Large Language Models in 2025 (8,627)
    • Online Shopping System using PHP, MySQL with Free Source Code (5,247)
    • login form in php and mysql , Step-by-Step with Free Source Code (4,904)

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme