express - What is meaning of locals in res.render (node.js)? -


what difference between below 2 code block in node.js (express + ejs)?

res.render('demo', {locals:{"variable":data}}); 

and

res.render('demo', {"variable":data}); 

when use one? can 1 please me out in this.

the correct way of passing variables view wollowing

res.render('demo', {"variable":data}); 

then have objet res.locals can append data , passed view.

for example if have middlewere authentication, can set auth variables before request arrives in route.

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

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -