ExpressJS: What is the difference between app.local and res.local?

Posted by aeyang on Stack Overflow See other posts from Stack Overflow or by aeyang
Published on 2012-09-25T20:19:30Z Indexed on 2014/06/05 3:26 UTC
Read the original article Hit count: 118

Filed under:
|
|
|

I'm trying to learn Express and in my app I have middleware that passes the session object from the Request object to my Response object so that I can access it in my views:

app.use((req, res, next) ->
  res.locals.session = req.session
  next()
)

But app.locals is available to the view as well right? So is it the same if I do app.locals.session = req.session? Is there a convention for the types of things app.locals and res.locals are used for?

I was also confused on what the difference is between res.render() and res.redirect()? When should each be used?

Thanks for reading. Any help related to Express is appreciated!

© Stack Overflow or respective owner

Related posts about node.js

Related posts about request