I'm trying to understand the order of execution, but everything is somehow confusing:

var ua = 'foo'; app.use(function(req, res, next){ ua = 'barr'; next(); }); app.use( session({ key: ua, secret: 'session_cookie_secret', store: sessionStore, resave: true, saveUninitialized: true }) ); 

as I understand it, middleware are executed in order (top-down), and in theory, the variable ua should be assigned the value bar , but this does not happen. explain why?

PS created an intermediate handler, because you need to assign a value from req for sessions


Is there a difference between the challenges:

 app.use(function(req, res, next){ session({ key: key, secret: 'session_cookie_secret', store: sessionStore, resave: true, saveUninitialized: true }) next(); }); # и app.use( session({ key: key, secret: 'session_cookie_secret', store: sessionStore, resave: true, saveUninitialized: true }) ); 
  • everything happens, just at the time of the call { key: ua, string ua = 'barr'; - Grundy
  • Is there a difference between the challenges - the greatest! and is. when the session function is executed and the parameter for it is calculated - Grundy
  • @Grundy еще не выполнилась строка - isn’t everything supposed to be done in order? first the value of the variable is assigned, then the next middleware is executed - where the session is called - monsiure
  • the bottom line is that in the case of app.use( session({ arguments for the session are not calculated inside the middleware. - Grundy
  • Here is a good screencast about middleware youtu.be/2Xp9yj3UIAg - stasovlas

0