View counter example:
varexpress=require('express')varsession=require('express-tiny-session')varcookieParser=require('cookie-parser')varapp=express();varsecret='my_secret';app.use(cookieParser(secret))app.use(session({secret:secret,signed:true}))app.use(function(req,res,next){varn=req.session.views||0req.session.views=++nres.end(n+' views')})app.listen(3000)name- The cookie name. Defaults toexpress:sess.secret- A string which will be used to signing cookie
The options can also contain any of the follow:
maxAge: a number representing the milliseconds fromDate.now()for expiryexpires: aDateobject indicating the cookie's expiration date (expires at the end of session by default).path: a string indicating the path of the cookie (/by default).domain: a string indicating the domain of the cookie (no default).secure: a boolean indicating whether the cookie is only to be sent over HTTPS (falseby default for HTTP,trueby default for HTTPS).secureProxy: a boolean indicating whether the cookie is only to be sent over HTTPS (use this if you handle SSL not in your node process).httpOnly: a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (trueby default).signed: a boolean indicating whether the cookie is to be signed (falseby default).