I was messing around with Express JS and was the using express-session. It didn't work if I didn't put the app.use(session())
middleware first
app.use(session({
name: 'server-session-cookie-id',
secret: 'my express secret',
saveUninitialized: true,
resave: true
}));
app.use('/', routes);
app.set("view engine", "pug");
app.set("views", path.join(__dirname + "/views"));
app.use(flash());
If the app.use(session())
written first it would say that the req.session.someVariable
was undefined.
Can someone explain how Express calls the app.use middleware?