title: My Node/Express session expires with every change to my code
body: <p>I am working on a local Node/Express app and am using <a href="https://www.npmjs.com/package/express-session" rel="nofollow noreferrer">express-session</a>.</p>
  
  <p>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?</p>
  
  <p>Here's how my session is set:</p>
  
  <pre><code>var day = 60000*60*24;
  req.session.expires = new Date(Date.now() + (30*day));          
  req.session.cookie.maxAge = (30*day);
  </code></pre>
  
  <p>I am using <a href="https://www.npmjs.com/package/nodemon" rel="nofollow noreferrer">Nodemon</a>, so my server restarts on every save. Is this why?</p>
  
  <p><strong>EDIT</strong>: looks like the issue is with restarting the server, not with the code change. Relevant answers here:</p>
  
  <p>(1) <a href="https://stackoverflow.com/questions/23260676/express-4-sessions-not-persisting-when-restarting-server">Express 4 Sessions not persisting when restarting server</a></p>
  
  <p>(2) <a href="https://stackoverflow.com/questions/5286073/node-js-server-restart-drops-the-sessions">Node.js server restart drops the sessions</a></p>