From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adding cookies and sessions to Express

Adding cookies and sessions to Express

From the course: Advanced Express

Start my 1-month free trial

Adding cookies and sessions to Express

- [Instructor] As shown in the previous video we will need cookie parser to read cookies from the raw request header. So I'm installing that now in npm install --save cookie-parser and we need to recall it in our app.js file. So somewhere on top of the file add, const cookieParser = require('cookie-parser'). CookieParser is a middleware. This means we also have to add it to the chain of middlewares via app.use. And for that I'm going down to line 24, right after the bodyParser. I will now add app.use(cookieParser). And we're calling it as a function So we have to add parentheses here in the end. From now on Express will give us cookies in request.cookies. Next, let's plug in the session management. For that install express session into install-- save express-session and to store the sessions in MongoDB I will install connect-mongo and now on top of app.js again I will bring in those modules first. The session module const session = require('express-session') and then I add the…

Contents