I'm using node.js to perform a DNS lookup to return and IP address (http://nodejs.org/api/dns.html). In this example, I can get my result to log correctly, though I'd rather be able to have access to the variable outside of the scope of the callback. How would this be possible?
My current code:
var domain = 'google.co.uk';
dns.lookup(domain, function (err, aRecord) {
if (err) throw err;
console.log(aRecord);
});
Ideally, I'd like to be able to perform something along the lines of:
var domain = 'google.co.uk';
var myfunction = dns.lookup(domain, function (err, aRecord) {
if (err) throw err;
return aRecord;
});
var result = myfuction(domain);