Creating the Profile Route and Page

Create the user profile page using the Pug templating language.Add programming logic to password protect the profile page for unauthorized users, or show user information for the currently logged in user.

GET /profile route

// GET /profilerouter.get('/profile',function(req,res,next){if(!req.session.userId){varerr=newError("You are not authorized to view this page.");err.status=403;returnnext(err);}User.findById(req.session.userId).exec(function(error,user){if(error){returnnext(error);}else{returnres.render('profile',{title:'Profile',name:user.name,favorite:user.favoriteBook});}});});