State Management: Cookies Session
State Management: Cookies Session
HTTP is stateless
In order to associate a request to any other request, you need a way to store user
data between HTTP requests
Cookies are used to transport data between the client and the server
Sessions allow you to store information associated with the client on the server
Cookies Session
Stored on the client side Stored on the server side
Can only store strings Can store objects
Can be set to a long lifespan When users close their browser, they also lose the session
You can pass an object as the value parameter - it is then serialized as JSON and
parsed by bodyParser() when received in the request
res.cookie('cart', { items: [1,2,3] });