Languages

Node.js - how to set session expiration time in Express.js cookie

0 points
Asked by:
Aaron1
568

How to set the session to last for 48 hours in Express.js cookie?

1 answer
3 points
Answered by:
Aaron1
568

In cookie, you need to specify maxAge with time in milliseconds.

Practical example:

app.use(
    session({
        // some properties here ...
        cookie: {
            maxAge: 48 * 60 * 60 * 1000 // 48 hours in milliseconds
        },
    })
);

See also:

  1. HTTP header Cache-Control max-age most common time used in seconds 
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join