Reputation: 43
Hi I am using this given middleware to show username userid etc on every template but this middleware is not working neither console.log working nor locals working in my ejs template. Please check why!
I am using this middleware in the last before app.listen.
app.use(function(req, res, next) {
console.log("Hello");
res.locals.username = req.session.username;
res.locals.userid = req.session.userid;
res.locals.w_id = req.session.w_id;
next();
});
Upvotes: 0
Views: 458
Reputation: 4643
I am using this middleware in the last before app.listen.
That's your issue, you must add this middleware before all the routes so that it will be called.
Upvotes: 1