req.session has no method 'touch'?
I was having the same error. It seems that if you're coming from express cookie sessions, it was possible to set req.session = {/* some arbitrary session object */}
. Obviously, req.session
has some methods on the instance that express needs.
So, just make sure you're not explicitly overriding req.session
anywhere in your code.
Try this:
req.session.user = { 'id': 123 }; req.session.pageviews = 1; // This too
Font: https://davidburgos.blog/expressjs-session-error-req-session-touch-not-function/
I was able to resolve this issue by using the cookie-parser middleware before using the cookie-session middleware:
var express = require('express')var cookieParser = require('cookie-parser');var cookieSession = require('cookie-session');var app = express();app.use(cookieParser());app.use(cookieSession());
Tested on Express 4