I get undefined req.session, with the following code:
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/static'));
app.use(require('json-middleware').middleware());
app.use(require('express-session')(
{resave: false,
saveUninitialized: false,
secret: 'secret',
cookie: { secure:false, maxAge: 60000 }}
));
app.post('/api/logIn', function(req, res) {
req.session.userName = req.body.userName;
res.end('O.K.');
});
Obviosusly this is not true authentication but please ignore that since I can't find the reason for this error. Cookie-parser is not needed anymore since express-session v1.5 (it's use is discouraged). I still tried it but the error (unsurprisingly) persists.