Setting Node.js Express session expiration time in SessionStore in stead of in cookie Setting Node.js Express session expiration time in SessionStore in stead of in cookie express express

Setting Node.js Express session expiration time in SessionStore in stead of in cookie


With the Session middleware, only the encrypted session ID is stored in the client side cookie. The expired date is stored as req.session.cookie.expires in the server side store. So we can add a custom middle to check whether current session is expired.

// ...app.use(express.cookieParser());app.use(express.session({secret:'yoursecret', cookie:{maxAge:6000}}));app.use(function(req, res, next) {  // if now() is after `req.session.cookie.expires`  //   regenerate the session  next();});// ...


I wrote the solution today as the project needed that.

Here it is:

https://github.com/expressjs/session/issues/173

There are instructions there.