Node.js – dns.resolveTxt() Method


The dns.resolveTxt() method uses the DNS protocol to resolve the text queries (TXT Records) for the hostname. The addresses argument passed to the callback function is a two-dimensional array that contains the array of text records available for the hostname.

Syntax

dns.resolveTxt(hostname, callback)

Parameters

  • hostname – This parameter takes input for hostname to be resolved

  • callback – This function will catch errors, if any.

    • records – Returns TXT records for the hostname.

Example 1

Create a file with the name "resolveTxt.js" and copy the below code snippet. After creating file use the command "node resolveTxt.js" to run this code.

// dns.resolveTxt() Demo Example

// Importing the dns module
const dns = require('dns');

// Passing the argument below
dns.resolveTxt('tutorialspoint.com', (err, records) => console.log('TXT Records: %j', records));

Output

C:\home
ode>> node resolveTxt.js TXT Records: [["google-site-verification=-RNrP1jBNMarh7tMQEgXtlBVUi000DUph-h8H7uSaQ"],["google-siteverification=S2zMIBQyc6WxHPiOdUzkWYvx_FKbf03xDOsI8OgG20A"],["v=sp f1 ip4:116.202.79.150 include:_spf.google.com -all"]]

Example 2

// dns.resolveTxt() Demo Example

// Importing the dns module
const dns = require('dns');

// Passing the argument below
dns.resolveTxt('google.com', (err, records) => console.log('TXT Records: %j', records));

Output

C:\home
ode>> node resolveNaptr.js TXT Records: [["facebook-domainverification=22rm551cu4k0ab0bxsw536tlds4h95"],["docusign=1b0a6754 -49b1-4db5-8540-d2c12664b289"],["apple-domainverification=30afIBcvSuDV2PLX"],["docusign=05958488-4752-4ef2- 95eb-aa7ba8a3bd0e"],["globalsign-smimedv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="],["google-siteverification=TV9- DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ"],["v=spf1 include:_spf.google.com ~all"],["google-siteverification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB0Hf5o"],["MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB"]]

Updated on: 29-Oct-2021

259 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements