Skip to content

Latest commit

 

History

History
14 lines (10 loc) · 665 Bytes

pass-data-to-all-views-with-locals.md

File metadata and controls

14 lines (10 loc) · 665 Bytes

Pass data to all views with res.locals object

If you have data that is used by every view in your Express app, you can pass that data via the res.locals object.

app.use(function(req, res, next) {
    res.locals.user = req.user;
    next();
});

This snippet from Stackoverflow.

The res.locals object merges with other data on render. See the documentation for more detail.