I have a function to find the MX records of a service and I want to save the value with the lowest priority in order to make a request to it. How can I store and retrieve this value?
const dns = require('dns');
const email = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8e6e6e688afa5a9a1a4e6aba7a5">[email protected]</a>'
let res = email.split('@').pop();
function getMxRecords(domain) {
return new Promise(function(resolve, reject) {
dns.resolveMx(domain, function(err, addresses) {
if (err) {
//console.log(err, err.stack)
resolve(null);
} else {
//console.log(addresses);
let copy = [...addresses];
//console.log(copy);
let theone = copy.reduce((previous, current) => {
if (previous.priority < current.priority) {
return current;
}
return previous;
});
resolve(theone);
}
});
});
}
let a = getMxRecords(res);
console.log(a);
I need to export this module so that I can make a request to it as shown below;
let socket = net.createConnection(25, request(email), () => {})
When attempting to use my function, I expect to receive either a string or an object with only one value. However, I always encounter the following issue:
Promise { }
Error in socket connect ECONNREFUSED 127.0.0.1:25