May seem like such a simple question, but it doesn't work and I would like to know why, and possibly understand if/how it can. For instance...
app.use(function (req, res, next) {
res.locals = {
ver: '1.0',
title: 'Awesome App ' + req.locals.ver,
author: 'Jack Diddly'
};
next();
});
...will error out, when it comes to using ver along with title, which I'm guessing would be since the locals haven't been completed yet as something that can be requested.
Steven Ventimiglia
Creative Technologist & Sr. Front-End Developer
I came across a simple solution and figured I'd post it, in case anyone else was trying to concat strings within their
res.locals.app.use(function (req, res, next) { req.locals = { ver: '1.0' }, res.locals = { title: 'Awesome App ' + req.locals.ver, author: 'Jack Diddly' }; next(); });Basically, you cannot use or request
res.localswithin the same array. However, that doesn't stop you from initiating a primary array (in this case,req.locals), and then assigning those to what would be your secondary array (which is nowres.locals.)You don't need to name the primary array
req.locals, either. Settling forreq.verworks as well, but I think naming the array withlocals, groups it with a relative name.