I have a function in project
function findParentID(parentName) {
Category.findOne({ categoryName: parentName }, function (err, foundParent) {
var parentID = foundParent.categoryID;
return parentID;
});
}
module.exports.findParentID = findParentID;
and when I try to call this function, I am getting undefined
in console.log()
This is how I am trying to call it
var parentName = req.body.parent_name;
var parentID = findParentID(parentName);
console.log(parentID);
based on my understanding, the function is not returning any value. How do I return a value from the function?