Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to use cookieSession in express

How to use cookieSession in express

Problem

I'm trying to use the built in cookieSession object of connect, but I cannot get it to work properly with express.

I have this app:

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'm getting this error:

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

Any ideas?

thanks

Problem courtesy of: mihai

Solution

What is the version of your connect module? The cookieSession middleware was first added in version 2.0.0. Run npm list|grep connect to make sure your connect version is at least 2.0.0 or higher.

Solution courtesy of: belltoy

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to use cookieSession in express

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×