June 2014
Intermediate to advanced
696 pages
38h 52m
English
When rendering a template, you may want to include dynamic data—for example, to render a page for user data just read from a database. In such a case, you can generate a locals object that contains properties that map to variable names defined in the templates. The express() app object provides the app.locals property to store local variables.
To assign a local template variable directly, you can use dot syntax. For example, the following code defines the local variables title and version:
app.locals.title = 'My App';app.locals.version = 10;
Read now
Unlock full access