I'm trying to create a function with node.js that checks the hash of an online file to see if it's been changed. Every time I call my function it always returns undefined. I understand the problem has something to do with asynchronous functions, but I don't quite understand how they work.
const crypto = require("crypto")
const request = require("request")
function checkHash(url, hash) {
request.get(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
if (crypto.createHash('md5').update(body).digest("hex") !== hash) {
return true;
} else {
return false;
}
}
});
}