You will probably want to use the rollback option for your session. This "forces the cookie to set on every response" and "resets expiration date". You want to set the switch to true.
Also note the "resave" parameter. This means that the session will be saved even if it is unmodified ... "You will probably want to set this option to true as well. Note that although the default value for this option is true, you must explicitly set the value. Based on the default value for this parameter, instead of explicitly specifying it, it is now deprecated.
Try something like:
app.use( session( { secret: 'keyboard cat', cookie: { maxAge: 60000 }, rolling: true, resave: true, saveUninitialized: false } ) );
Here is the documentation. Take a look in the "Options" and "options.resave" sections: https://github.com/expressjs/session .
source share