Node.js dns.lookup() Method (original) (raw)

Last Updated : 10 Sep, 2024

The

**dns.lookup() method

is an inbuilt application programming interface of the dns module which is used to resolve IP addresses of the specified hostname for given parameters into the first found A (IPv4) or AAAA (IPv6) record.

**Syntax:

dns.lookup( hostname, options, callback )

**Parameters:

This method has three parameters as mentioned above and described below:

// Accessing dns module
const dns = require('dns');
// Setting options for dns.lookup() method
const options = {

// Setting family as 6 i.e. IPv6  
family: 6,  
hints: dns.ADDRCONFIG | dns.V4MAPPED,  

};
// Calling dns.lookup() for hostname geeksforgeeks.org
// and displaying them in console as a callback
dns.lookup('geeksforgeeks.org', options, (err, address, family) =>
console.log('address: %j family: IPv%s', address, family));
`

// Accessing dns module
const dns = require('dns');
// Setting options for dns.lookup()
// method, all as true
const options = {
all:true,
};
// Calling dns.lookup() for hostname
// geeksforgeeks.org and displaying
// them in console as a callback
dns.lookup('geeksforgeeks.org', options, (err, addresses) =>
console.log('addresses: %j', addresses));
`