Referring to this documentation I am getting the ip address from domain name inside console.log
the code looks like so:
const dns = require('dns');
dns.lookup('iana.org', (err, address, family) => {
console.log('address: %j family: IPv%s', address, family);
});
Output of console.log is fine.
However I can't get address outside that scope. The return statement of the dns.lookup function is an object.
What I've tried so far:
const ipAddress = dns.lookup("www.aWebSiteName.am", (err, address, family) => {
if(err) throw err;
return address;
});
console.log(ipAddress);
I am getting:
GetAddrInfoReqWrap {
callback: [Function],
family: 0,
hostname: 'www.aWebSiteName.am',
oncomplete: [Function: onlookup] }