npm install --save express-session
Storing sessions in memory
This is just for development. In production we will not store sessions in memory as with lot of users it can easily crash.
We need to first add sesssion middleware.
app.js
controllers/auth.js
After postLogin
new cookie will be created in our browser, we can see it in developer console under Application/Cookies.
Storing sessions in database
npm install --save connect-mongodb-session
This is for production. We will use MongoDB for storing sessions.
app.js
controllers/auth.js
This remains the same, session are now stored in MongoDB.