Introduction to cookie and session

What is cookie?

Cookie is a bit of data stored by the browser and sent to the server with every request.
When you visit a web page, a cookie is created and stored in your browser. Next time when you visit that web page the cookie is sent to the server so, the server knows you have visited the page before.

On the client side, in the browser, only a unique identifier is stored. It is called “session id”. This session id is pass to the web server every time a HTTP request is make to the server (like app.post() or route.post()). The session itself is stored on the server.

What is session?

A session is a collection of data stored on the server. It is associated with a given user usually via a cookie (containing the session id).

The cookie-parser and express-session are the Express.js libraries for cookie and session respectively.

Leave a Reply