I am trying to pass the result of a query in my opinion to Express. The query is performed using mongodb, which counts the collective points of collective users.
When I try to pass the score through a variable, I get
ReferenceError: /Sites/test/views/dashboard.ejs:76
which refers to <% = totalpoints%> in my ejs view. Below is my code in app.js
app.get('/dashboard', function(req, res) { User.find({}, function(err, docs) { console.log(docs); }); User.find({ points: { $exists: true } }, function(err, docs) { var count = 0; for (var i = 0; i < docs.length; i++) { count += docs[i].points; } return count; console.log('The total # of points is: ', count); }); var totalpoints = count; res.render('dashboard', { title: 'Dashboard', user: req.user, totalpoints: totalpoints }); });
Any ideas how I can pass the result of the query through?
source share