Languages

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

0 points
Asked by:
Dirask Community
6810

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

1 answer
0 points
Answered by:
Dirask Community
6810

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

Practical example:

app.use(
  session({
    key: 'exampleKey',
    secret: 'exampleSecret',
    resave: false,
    saveUninitialized: false,
    cookie: {
      maxAge: 48*60*60*1000 // 48 hours in milliseconds
    },
  })
);
0 comments Add comment
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