Node.js dns.resolveTxt() Method
The dns.resolveTxt() method is an inbuilt application programming interface of the dns module which is used to resolve TXT or text queries records for the specified hostname using DNS protocol.
Syntax:
dns.resolveTxt( hostname, callback )
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.
- callback: It specifies a function to be called after DNS resolution of the hostnames.
- error: It specifies error if generated.
- addresses: It is an array of string that signifies the returned text queries records for the hostname.
Return Value: This method returns error, addresses through callback function. These data are passed as parameters to the callback function.
Below examples illustrate the use of dns.resolveTxt() method in Node.js:
Example 1:
const dns = require( 'dns' );
dns.resolveTxt( 'geeksforgeeks.org' , (err,
addresses) => console.log( 'TXT records: %j' , addresses));
|
Output:
TXT records: [
["fob1m1abcdp777bf2ncvnjm08n"],
["v=spf1 include:amazonses.com include:_spf.google.com -all"]
]
Example 2:
const dns = require( 'dns' );
dns.resolveTxt( 'google.com' , (err,
addresses) => console.log( 'TXT records: %j' , addresses));
|
Output:
TXT records: [
["globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="],
["v=spf1 include:_spf.google.com ~all"],
["docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"],
["facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95"],
["docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"]
]
Note: The above program will compile and run by using the node index.js
command.
Reference: https://nodejs.org/api/dns.html#dns_dns_resolvetxt_hostname_callback
Last Updated :
13 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...