expressjs / expressjs/express

app.locals not passed down to a subapp

Open
#3,057 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
69.5k
Forks
25k
Avg merge
4d 20h
Merged PRs (30d)
9

Description

In this example I would expect that `appTitle` will be available to me, because this is what is says in [docs](http://expressjs.com/en/4x/api.html#app.locals).

> The app.locals object has properties that are local variables within the application.

The same way I don't have to set the `'view engine'`, it just uses the one from the parent. But it's not the case, `appTitle` becomes `undefined`.

``` javascript
var express = require('express');

var app = module.exports = express();

app.set('view engine', 'pug');
app.locals.appTitle = 'yay';

var subapp = express();

subapp.get('/', function (req, res) {
res.render('index', {myVar: 'global var'});
});

app.use(subapp);

var port = 5000;
app.listen(port, () => console.log('running on ' + port));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.