Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. // Use the session middleware
  2. app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
  3.  
  4. // Access the session as req.session
  5. app.get('/', function(req, res, next) {
  6. if (req.session.views) {
  7. req.session.views++
  8. res.setHeader('Content-Type', 'text/html')
  9. res.write('<p>views: ' + req.session.views + '</p>')
  10. res.write('<p>expires in: ' + (req.session.cookie.maxAge / 1000) + 's</p>')
  11. res.end()
  12. } else {
  13. req.session.views = 1
  14. res.end('welcome to the session demo. refresh!')
  15. }
  16. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement