SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top