Nodejs, how to set express session cookies so as not to expire at any time

In the expression, does the maxAge=null parameter maxAge=null in the session cookie, does the session cookie not expire?

+7
session
source share
2 answers

If you do not want the session to expire, set the cookie expiration date to a future date:

 app.use(session({ store: sessionStore, secret: config.session.secret, cookie: {expires: new Date(253402300000000)} // Approximately Friday, 31 Dec 9999 23:59:59 GMT })) 

See express session documents .

If you are concerned about using dates in the future, try new Date(2147483647000) (Tue, Jan 19, 2038 03:14:07 GMT, which is 2^31 - 1 in milliseconds)

+9
source share

Express uses the Connect session middleware to process this:

By default, cookie.maxAge is null, that is, the "expires" parameter is not equal so the cookie becomes a cookie for the browser. When the user closes the browser, the cookie (and session) will be deleted.

+3
source share

All Articles