node.jsnode.js-connect

Accessing the session object after a POST


I'm using express.js with the session middleware. This is my code:

var express = require('express'),
    app = express.createServer();

app.configure(function () {
   app.use(express.cookieParser())
      .use(express.session({ secret: 'blabla' }));
});

app.post('/login', function (request, response) {
    console.log(request.session); // Prints `undefined`
});

How can I access the session object?


Solution

  • Your exact code with app.listen() appended works for me. Make sure you're using the latest express. I tried on express v2.5.1 and node v0.6.5.