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
From the course: Advanced Express
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding cookies and sessions3m 54s
-
(Locked)
Adding cookies and sessions to Express5m
-
(Locked)
Inspecting the session object2m 18s
-
Introduction to Passport1m 39s
-
(Locked)
Adding Passport to Express3m 55s
-
(Locked)
Setting up an authentication strategy for Passport5m 18s
-
(Locked)
Serializing and deserializing users3m 25s
-
(Locked)
Creating a login form with Passport5m 14s
-
(Locked)
Providing a logout link2m 1s
-
(Locked)
Authentication vs. authorization1m 23s
-
(Locked)
Protecting routes3m 35s
-
-
-
-