The
dnsPromises.resolveMx() method is an inbuilt application programming interface of promises object of the dns module which is used to resolve MX or mail exchange records for the specified hostname using DNS protocol.
Syntax:
dnsPromises.resolveMx( hostname )
Parameters: This method accepts a single parameter as mentioned above and described below:
- hostname: this parameter specifies a string which denotes the hostname to be resolved.
Return Value: This method returns error, addresses.
Below examples illustrate the use of
dnsPromises.resolveMx() method in Node.js:
Example 1:
Output:
for google :
[ { exchange: 'alt4.aspmx.l.google.com', priority: 50 },
{ exchange: 'alt3.aspmx.l.google.com', priority: 40 },
{ exchange: 'aspmx.l.google.com', priority: 10 },
{ exchange: 'alt1.aspmx.l.google.com', priority: 20 },
{ exchange: 'alt2.aspmx.l.google.com', priority: 30 } ]
Example 2:
Output:
from async:
[ { 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 },
{ exchange: 'alt2.aspmx.l.google.com', priority: 5 } ]
Note: The above program will compile and run by using the
node index.js command.
Reference: https://nodejs.org/api/dns.html#dns_dnspromises_resolvemx_hostname