This is a simple function which will get a post url and return the post id of that url.
function findPostIdByUrl (url) {
var id;
Post.findOne({url}, '_id', function (err, post) {
if (err) throw err;
id = post.id;
});
return id;
}
but it doesn't return the actual id, because it run asynchronously. I want to first run Post.fin... code which will assign the post id to the id variable, and then run return id.
I've tried my best but I didn't figure out how can I do that. Is there any way to accomplish that?(whether by using async.js or not)