What's difference with express-session and cookie-session?

后端 未结 7 1299
既然无缘
既然无缘 2021-01-30 00:00

I am new with Express. As Express 4.x has removed bundled middlewares. Any middleware I want to use should be required. When I read the README with exp

7条回答
  •  执笔经年
    2021-01-30 00:30

    express-session stores the session identifier in the cookie while the actual session data resides in backend session store like connect-redis, where as cookie-session allows you to store the session data in a cookie (client-side).

    From the documentation of cookie-session:

    A user session can be stored in two main ways with cookies: on the server or on the client. This module stores the session data on the client within a cookie, while a module like express-session stores only a session identifier on the client within a cookie and stores the session data on the server, typically in a database.

    The main advantage of using cookie-session is when you have a clustered node.js app, then you don't have to rely on sharing session data between forked processes.

提交回复
热议问题