Search code examples
node.jsexpressexpress-sessioncookie-session

What is "cookie-parser" middleware?


While creating back-end apps with express.js, I have used express-session and cookie-session.

But, recently I found out this cookie-parser package on npm. It's pretty popular.

My question is,

What is cookie-parser and how is it different from express-session or cookie-session ?


Solution

  • Cookie Parser parses the incoming cookies from request to JSON value.

    Whereas cookie-session or express-session is to maintain session on your server.

    When your frontend sends a request, if cookies are set up, it will send some cookies based on usage, which by default are hard to interpret by server, so here cookie parser will parse those for easy understand ability. Which in turn could be used to create/maintain sessions or Authenticate (Depends upon cookie usage).