Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js DNS

  • Difficulty Level : Medium
  • Last Updated : 14 Oct, 2021


DNS is a node module used to do name resolution facility which is provided by the operating system as well as used to do an actual DNS lookup.

No need for memorising IP addresses – DNS servers provide a nifty solution of converting domain or subdomain names to IP addresses.

Example 1:

// Include 'dns' module and create its object
const dns = require('dns');
const website = '';
// Call to lookup function of dns
dns.lookup(website, (err, address, family) => {
  console.log('address of %s is %j family: IPv%s'
           website, address, family);
// Execute using $ node <filename>


address of is "" family: IPv4

Example 2:

// Include 'dns' module and create its object
var dns = require('dns');
// Call to reverse function along with lookup function.
     function onLookup(err, address, family) {
    console.log('address:', address);
    dns.reverse(address, function (err, hostnames) {
      console.log('reverse for ' + address + ': ' 
             + JSON.stringify(hostnames));
// Execute using $ node <filename>


reverse for [""]


My Personal Notes arrow_drop_up
Recommended Articles
Page :