First of all, I'm new with node and express, so I think I'm losing something in the logic of express.js.
I'm trying to show the response from an API in frontend, but I can't even get it right in the backend.
routes/index.js
exports = module.exports = function (app) {
// Views
app.get('/', routes.views.index);
};
views/index.js
binance.prices((error, ticket) => {
res.locals.ticket = ticket;
});
console.log(res.locals.ticket);
The last line is printing undefined
and I don't understand why. Is because is out scope? or is the callback? I think is an asynchronicity problem, but I don't know how to solve it.
Any help will be appreciated.