I am creating a website which uses an api to dispaly football (soccer) scores, fixtures etc. I have tried to create a global variable to save the request data to and then pass into ejs however this doesn't seem to work.
router.get('/stats', (req, res) => {
request(options, function (error, response, body) {
if (error) throw new Error(error);
top_scorer_data = JSON.parse(body)
});
request(options2, function (error, response, body) {
if (error) throw new Error(error);
top_assists_data = JSON.parse(body)
});
request(options3, function (error, response, body) {
if (error) throw new Error(error);
top_red_cards_data = JSON.parse(body)
});
request(options4, function (error, response, body) {
if (error) throw new Error(error);
top_yellow_cards_data = JSON.parse(body)
});
res.render('bundesliga/stats', {})
})