1
I’m trying to make an Next call in my Node JS Express app and sending the data to my index.ejs file. The problem is that i can see the data in my callApijavascript file but i cant access the Response in my app.js (Undefined value).
This is the Relevant code from my app js. file:
//iNDEX pAGE RENDER
app.get('/', function (req, rep) {
var response = callApi.GetAll();
var users = response.users;
var activities = response.activities;
console.log('Users ' + users);
console.log('Activities ' + activities);
rep.render('index', {
users: users,
activities: activities
});
});
Here’s my callApi.js the logs here Return the api data Perfectly
var GetAll = function () {
axios.all([
axios.get(initGet.uri + 'users/'),
axios.get(initGet.uri + 'activities/')
])
.then(axios.spread(function (userResponse, activitiesResponse) {
console.log('User', userResponse.data);
console.log('Activities', activitiesResponse.data);
return {
users: userResponse.data,
activities: activitiesResponse.data
};
}));
};
module.exports = {
GetAll: GetAll
};
My Error when i run index.ejs {"error":{"message":"Cannot read Property 'users' of Undefined"}}
Thanks in Advance.
Please translate your question, this is Stackoverflow in English
– Ricardo Pontual