What is the difference between 'session' and 'cookieSession' middleware in Connect/Express?

gfaceless picture gfaceless · Apr 1, 2013 · Viewed 9.4k times · Source

There are two session-related middlewares bundled with Connect/Express. What is the difference? How do I choose?

I'm assuming that session middleware is the same as cookieSession middleware, but with an extra store mechanism.

Answer

jmar777 picture jmar777 · Apr 1, 2013

The session middleware implements generic session functionality with in-memory storage by default. It allows you to specify other storage formats, though.

The cookieSession middleware, on the other hand, implements cookie-backed storage (that is, the entire session is serialized to the cookie, rather than just a session key. It should really only be used when session data is going to stay relatively small.