Node.js – dnsPromises.resolveAny() Method


The dnsPromises.resolveAny() method uses the DNS protocol to resolve all records (this is also known as ANY or * query). The promise is resolved with an array containing various types of records.

TypeProperties
'A'IPv4 address
'AAAA'IPv6 address
'Any'Any Records
MXMail Exchange Records
NAPTRName authority pointer records
NSName server records
PTRPointer Records
SOAStart of Authority Records
SRVService Records
TXTText Records
CNAMECanonical Name Records

Syntax

dnsPromises.resolveAny(hostname)

Parameters

  • hostname - This parameter takes input for the hostname to be resolved.

Example 1

Create a file with the name "resolveAny.js" and copy the following code. After creating the file, use the command "node resolveAny.js" to run this code, as shown in the example below −

// Node.js program to demonstrate the
// dnsPromises.resolveAny() method

// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;

// Calling dnsPromises.resolveAny() method
dnsPromises.resolveAny('tutorialspoint.com').then((response) => { 
   console.log("records :", response);
});

Output

C:\home
ode>> node resolveAny.js records: [ {"address":"95.217.74.146","ttl":600,"type":"A"}, {"exchange":"alt2.aspmx.l.google.com","priority":5,"type":"MX"}, {"exchange":"alt1.aspmx.l.google.com","priority":5,"type":"MX"}, {"exchange":"aspmx.l.google.com","priority":1,"type":"MX"}, {"exchange":"alt4.aspmx.l.google.com","priority":10,"type":"MX"}, {"exchange":"alt3.aspmx.l.google.com","priority":10,"type":"MX"}, {"value":"pdns13.domaincontrol.com","type":"NS"}, {"value":"pdns14.domaincontrol.com","type":"NS"}, {"entries":["google-site-verification=-RNrP1jBNMarh7tMQEgXtlBVUi000DUph-h8H7uSaQ"],"type":"TXT"}, {"entries":["google-siteverification=S2zMIBQyc6WxHPiOdUzkWYvx_FKbf03xDOsI8OgG20A"],"type" :"TXT"}, {"entries":["v=spf1 ip4:116.202.79.150 include:_spf.google.com - all"],"type":"TXT"}, {"nsname":"pdns13.domaincontrol.com","hostmaster":"dns.jomax.net" ,"serial":2021051700,"refresh":28800,"retry":7200,"expire":604800 ,"minttl":600,"type":"SOA"} ]

Example 2

// Node.js program to demonstrate the
// dnsPromises.resolveAny() method

// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;

// Calling dnsPromises.resolveAny() method
dnsPromises.resolveAny('localhost').then((response) => {
   console.log("Address :", response);
});

Output

C:\home
ode>> node resolveAny.js Address : [ { address: '127.0.0.1', ttl: 0, type: 'A' }, { address: '::1', ttl: 0, type: 'AAAA' } ]

Updated on: 24-Nov-2021

107 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements