I am creating a function for checking MX record in NodeJs.
I am trying to achieve the return value in 0 / 1
but it return error dns is not defined
.
I want to achieve the output when I run this code below
if(!mxcheck("xyz@domain.com")) {
console.log("you have entered an invalid email")
}
exports.mxcheck = async function (email) {
dns.resolve(email.split("@")[1], "MX", function (err, addresses) {
if (err) {
return 1;
} else if (addresses && addresses.length > 0) {
return 0;
}
});
};