VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-dnspromises-resolve-method/

⇱ Node.js dnsPromises.resolve() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js dnsPromises.resolve() Method

Last Updated : 10 Sep, 2024

The

dnsPromises.resolve() method

is an inbuilt application programming interface of the promises object of dns module which is used to resolve hostname into an array of the resource records.

Syntax:

dnsPromises.resolve( hostname, rrtype )

Parameters:

This method has two parameters as mentioned above and described below:

  • hostname: This parameter specifies a string which denotes the hostname to be resolved.
  • rrtype: It specifies resource record type. Its default value is 'A'. The values are from 'A', 'AAAA', 'ANY', 'CNAME', 'MX', 'TXT', 'NS', 'NAPTR', 'PTR', 'SOA', 'SRV'.
    • A: IPv4 address
    • AAAA: IPv6 address
    • ANY: Any records
    • CNAME: Canonical name records
    • MX: Mail exchange records
    • NAPTR: Name authority pointer records
    • NS: Name server records
    • PTR: Pointer records
    • SOA: Start of authority records
    • SRV: Service records
    • TXT: Text records

Return Value:

This method returns error, records. Below examples illustrate the use of

dnsPromises.resolve() method

in Node.js:

Example 1:

Output:

[ 'ns-869.awsdns-44.net',
'ns-245.awsdns-30.com',
'ns-1520.awsdns-62.org',
'ns-1569.awsdns-04.co.uk' ]

Example 2:

Output:

from async:
[ { exchange: 'alt2.aspmx.l.google.com', priority: 5 },
{ exchange: 'aspmx.l.google.com', priority: 1 },
{ exchange: 'alt3.aspmx.l.google.com', priority: 10 },
{ exchange: 'alt4.aspmx.l.google.com', priority: 10 },
{ exchange: 'alt1.aspmx.l.google.com', priority: 5 }
]

Example 3:

Output:

[ '8.8.8.8' ]

Example 4:

Output:

(node:12752) ExperimentalWarning: The dns.promises API is experimental
[ [ 'v=spf1 include:amazonses.com include:_spf.google.com -all' ],
[ 'fob1m1abcdp777bf2ncvnjm08n' ] ]

Note:

The above program will compile and run by using the

node index.js

command.

Reference:

https://nodejs.org/api/dns.html#dns_dnspromises_resolve_hostname_rrtype
Comment

Explore