mirror of
https://github.com/expressjs/expressjs.com.git
synced 2026-02-21 19:41:33 +00:00
18 lines
578 B
Plaintext
18 lines
578 B
Plaintext
section
|
|
h3(id='res.locals') res.locals
|
|
|
|
p.
|
|
Response local variables are scoped to the request, thus only
|
|
available to the view(s) rendered during that request / response
|
|
cycle, if any. Otherwise this API is identical to <a href="#app-locals">app.locals</a>.
|
|
|
|
p.
|
|
This object is useful for exposes request-level information such as the
|
|
request pathname, authenticated user, user settings etcetera.
|
|
|
|
+js.
|
|
app.use(function(req, res, next){
|
|
res.locals.user = req.user;
|
|
res.locals.authenticated = ! req.user.anonymous;
|
|
next();
|
|
}); |