- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – dnsPromises.resolveTxt() Method
The dnsPromises.resolveTxt() method uses the DNS protocol to resolve the text search (TXT records) for the hostname. The promise is resolved with a twodimensional array of the text records available for the hostname on success.
Syntax
dnsPromises.resolveTxt(hostname)
Parameters
It takes only one parameter
hostname – This parameter takes input for the hostname to be resolved.
Example 1
Create a file with the name "resolveTxt.js" and copy the following code snippet. After creating the file, use the command "node resolveTxt.js" to run this code.
// dns.resolveTxt() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Passing IP to find the hostname TXT records dnsPromises.resolveTxt('tutorialspoint.com').then((response) => { console.log("TXT Records: ", response); })
Output
TXT Records: [ [ 'google-siteverification=S2zMIBQyc6WxHPiOdUzkWYvx_FKbf03xDOsI8OgG20A' ], [ 'v=spf1 ip4:116.202.79.150 include:_spf.google.com -all' ], [ 'google-site-verification=-RNr-P1jBNMarh7tMQEgXtlBVUi000DUphh8H7uSaQ' ] ]
Example 2
// dns.resolveTxt() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Setting ttl as true const options={ ttl:true, }; // Calling dnsPromises.resolveTxt() method // asynchronously (async function() { const records = await dnsPromises.resolveTxt( 'google.com', options); // Printing records console.log("TXT Records: ", records); })();
Output
TXT Records: [ [ 'MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB' ], [ 'apple-domain-verification=30afIBcvSuDV2PLX' ], ['globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8='], [ 'docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e' ], [ 'docusign=1b0a6754-49b1-4db5-8540-d2c12664b289' ], [ 'v=spf1 include:_spf.google.com ~all' ], [ 'google-site-verification=TV9-DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ' ], [ 'facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95' ], [ 'google-siteverification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB-0Hf5o' ] ]
Advertisements
To Continue Learning Please Login
Login with Google