I have been pulling my hair out for the last day in hoping I can find a way of getting around or fixing this. I have tried everything I can think of, and no matter what, the function always returns undefined
.
What I am trying to do is getting the information from The Movie Database, but via a function with a variable of the film's ID number. It retrieves the information perfectly, but the issue is, it won't return the JSON array. It always returns undefined
and I'm unsure what is causing this.
function getMovieData (movieid) {
var data;
moviedb.movieInfo({id: movieid}, (err, res) => {
data = res;
})
return data;
}
The return value would be returned and would be used via Express and Handlebars to display to the user.
I am genuinely confused as to why this isn't working. Any help would be appreciated.