I have a function named IsValidUrl()
that I need that returns some values by its situation(false or true). But inside of this function I have another function that won't let to pass the values to IsValidUrl()
.
var validUrl = await isValidUrl();
if (!validUrl) {
console.log(validUrl); ** //validUrl is undefined**
return res.status(404).send('not found');
}
function isValidUrl() {
Post.findOne({
url: req.params.path
}, function(err, result) {
if (err) {
throw err
} else if (!result) {
return false
} else {
return true
}
})
}
How can I send the returned values to the IsValidUrl()
?