Node.js – dns.resolveNaptr() Method


The dns.resolveNaptr() method uses the DNS protocol to resolve regular expression based words (NAPTR records) for the hostname. The addresses argument passed to the callback function will contain an array of objects with the following properties −

  • flags

  • service

  • regexp

  • replacement

  • order

  • preference

Syntax

dns.resolveNaptr(hostname, callback)

Parameters

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

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

    • Records – Returns NAPTR records for the hostname.

Example 1

Create a file "resolveNaptr.js" and copy the following code snippet. After creating the file, use the command "node resolveNaptr.js" to run this code.

// dns.resolveNaptr() Demo Example

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

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

Output

QueryReqWrap {
   bindingName: 'queryNaptr',
   callback: [Function],
   hostname: 'tutorialspoint.com',
   oncomplete: [Function: onresolve],
   ttl: false,
   channel: ChannelWrap {} }
NAPTR Records: undefined

Example 2

// dns.resolveNaptr() Demo Example

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

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

Output

NAPTR Records: undefined

Updated on: 29-Oct-2021

40 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements