My code in the controller that generates the user template on which the data will be displayed looks like this:
exports.getDashboard = (req, res, next) => {
userId = req.user._id;
Stocks.find({ userId: userId })
.then(stocks => {
res.render('user/dashboard', {
pageTitle: 'Dashboard',
path: '/user/dashboard',
stock: stock,
userId: userId,
});
})
}
the code that receives this data to create the graph looks like this:
const userId = '<%= userId %>';
const eventSource = new EventSource('/user/dashboard/' + userId);
I don't know how to make sse send data to /user/dashboard/:userId. I have tried various methods but sse only works for me when I do not execute res.render only res to send and I want on this url to execute the sending of data but also want to have my view dashboard.ejs.