DNS is a node module used to do name resolution facility which is provided by the operating system as well as used to do an actual DNS lookup.
Advantage: No need for memorizing IP addresses – DNS servers provide a nifty solution for converting domain or subdomain names to IP addresses.
Example 1: In this example, we will print the address of GeeksforGeeks on the console.
javascript
const dns = require('dns');
const website = 'geeksforgeeks.org';
dns.lookup(website, (err, address, family) =>; {
console.log('address of %s is %j family: IPv%s',
website, address, family);
});
|
Output:
address of geeksforgeeks.org is "52.25.109.230" family: IPv4
Example 2: In this example, we will print the address of the GeeksforGeeks.
javascript
const dns = require('dns');
dns.lookup('www.geeksforgeeks.org',
function onLookup(err, address, family) {
console.log('address:', address);
dns.reverse(address, function (err, hostnames) {
console.log('reverse for ' + address + ': '
+ JSON.stringify(hostnames));
});
});
|
Output:
address: 52.222.176.140
reverse for 52.222.176.140: ["server-52-222-176-140.bom52.r.cloudfront.net"]
Reference: https://nodejs.org/docs/latest-v9.x/api/dns.html#dns_dns
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
27 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...