How to use cookie session in express

I am trying to use the built-in cookieSession object to connect, but I cannot get it to work correctly with an expression.

I have this application:

 var express = require('express'); var connect = require('connect'); var app = express.createServer(); app.configure(function() { app.use(express.logger()); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser('whatever')); app.use(connect.cookieSession({ cookie: { maxAge: 60 * 60 * 1000 }})); }); app.get('/', function(req, res) { res.render('root'); }); app.listen(3000); 

I get this error:

 TypeError: Cannot read property 'connect.sess' of undefined at Object.cookieSession [as handle] 

Any ideas?

thanks

+8
express connect
source share
3 answers

What is the version of your connect module? The average cookieSession software was first added in version 2.0.0. Run npm list|grep connect so that your version of connect is at least 2.0.0 or higher.

+1
source share

Sessions will not work if you do not have these 3 in this order:

 app.use(express.cookieParser()); app.use(express.cookieSession()); app.use(app.router); 

Works like a charm after that.

see below: https://stackoverflow.com>

+12
source share

I also had this problem. It turned out that everyauth was among the modules related to connecting 1.7.5, after removing npm allauth, all the problems that were gone.

+1
source share

All Articles