Adding Locals

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;

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.255.24