Session using NodeJS and Express 4.x (req.session undefined) Session using NodeJS and Express 4.x (req.session undefined) express express

Session using NodeJS and Express 4.x (req.session undefined)


The problem is that the routes are set up before any other middleware. Move this line:

require('./router/main')(app, language, connection, logger);

after this:

app.use(session({    secret: 'pecuniamsekretsession',    resave: false,    saveUninitialized: true,    cookie: { secure: true }}));

in your server.js.