I'm learning Node.js and I'm trying to make a site where people can review movies. Everything works so I'm adding a feature that grabs the poster. I have this callback setup but I can't seem to figure out why it isn't working. It logs to the console fine, but nothing returns to the server.
function getPoster(title) {
var dataret;
imdbId(title, function (err, imdb_id) {
if (!err) {
console.log(imdb_id);
imdb(imdb_id, (err, data) => {
if (err) {
console.log(err.stack);
}
if (data) {
console.log(data);
}
dataret = data;
});
}
});
return dataret;
}
app.get('/getposter/:id', function (req, res) {
// IT WORKS UP TO HERE
res.setHeader('Content-Type', 'application/json');
res.status(200).send({ json: JSON.stringify(getPoster(req.params.id)) });
});