Reputation: 502
Middleware.js
exports.initLocals = function (req, res, next) {
res.locals.navLinks = [
{ label: 'Home', key: 'home', href: '/' },
{ label: 'Blog', key: 'blog', href: '/blog' },
{ label: 'Contact', key: 'contact', href: '/contact' },
{ label: 'Gallery', key: 'gallery', href: '/gallery' },
{ label : 'Research', key : 'research' , href : '/research'},
{ label : 'Publications', key : 'publications', href : '/publications'},
{ label : 'Teaching Initiatives', key : 'teaching', href : '/teaching-initiatives'}
];
res.locals.user = req.user;
userInfo = req.user;
next();
};
app.js
var middleware = require('./routes/middleware');
console.log(middleware.initLocals.userInfo);
app.js console is outputting undefined because I am accessing the variable before the request is made. Is there any other way to get the userInfo by pre-requesting. I feel that there must be way!
Upvotes: 2
Views: 240
Reputation: 52
Try to print middleware.initLocals only, or maybe the problem rely on the path which you required from it . hope that help you :)
Upvotes: 1