Node.js – dns.resolveNs() Method


The dns.resolveNs() method uses the DNS protocol to resolve the nameserver records (NS Records) for the hostname. The addresses argument passed to the callback function will contain an array of nameserver records for the hostname.

Syntax

dns.resolveNs(hostname, callback)

Parameters

The above parameters are defined as below −

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

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

    • records – Returns the nameserver (NS) records for the hostname.

Example 1

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

// dns.resolveNs() Demo Example

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

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

Output

NS Records: undefined

Example 2

// dns.resolveNs() Demo Example

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

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

Output

NS Records: undefined

Updated on: 29-Oct-2021

38 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements