Node.js - dns.resolve6() Method


The dns.resolve6() method uses the DNS protocol to resolve the IPv6 addresses (AAAA records) for the hostname. The addresses argument that is passed to the callback will contain an array of IPv6 addresses.

Syntax

dns.resolve6(hostname, [options], callback)

Parameters

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

  • options – It can have the following options −

    • ttl – This defines the Time-To-Live (TTL) for each record.

Example 1

Create a file with the name "resolve6.js" and copy the following code snippet. After creating the file, use the command "node resolve6.js" to run this code as shown in the example below −

// dns.resolve6() Demo Example

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

// Passing a single dns to get values
dns.resolve6('tutorialspoint.com', (err, address) => console.log('address: %j', address));

Output

C:\home
ode>> node resolve6.js address: undefined

Example 2

// dns.resolve6() Demo Example

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

// Setting the ttl option as true
const options = {
   ttl: true,
};

// Passing the dns address below
dns.resolve6('google.com', options, (err, address) => console.log('address: %j', address));

Output

C:\home
ode>> node resolve6.js address: [{"address":"2404:6800:4002:81d::200e","ttl":231}]

Updated on: 17-Jan-2022

129 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements