1

I am working on a local Node/Express app and am using express-session.

To test my code, I need to log into a user account. Every time I make a change in my code - even if I just add a space - the session ends and I get logged out. With no changes, my session persists as intended. Why?

Here's how my session is set:

var day = 60000*60*24;
req.session.expires = new Date(Date.now() + (30*day));          
req.session.cookie.maxAge = (30*day);

I am using Nodemon, so my server restarts on every save. Is this why?

EDIT: looks like the issue is with restarting the server, not with the code change. Relevant answers here:

(1) Express 4 Sessions not persisting when restarting server

(2) Node.js server restart drops the sessions

Max Pekarsky
  • 590
  • 2
  • 6
  • 20

1 Answers1

1

Looks like the issue is with restarting the server, not with the code change. By default, sessions are stored in MemoryStore. Relevant answers here:

(1) Express 4 Sessions not persisting when restarting server

(2) Node.js server restart drops the sessions

Max Pekarsky
  • 590
  • 2
  • 6
  • 20