Implementing the Get User Profile Route

Listing 26.6 implements the getUserProfile route. This handler finds the user by using the user id that is stored in req.session.user. If the user is found, a JSON representation of the user object is returned in the request. If the user is not found, a 404 error is sent.

Listing 26.6 users_controller.js-getUserProfile: Implementing the route to get user profiles for the Express server


48 exports.getUserProfile = function(req, res) {
49   User.findOne({ _id: req.session.user })
50   .exec(function(err, user) {
51     if (!user){
52       res.json(404, {err: 'User Not Found.'});
53     } else {
54       res.json(user);
55     }
56   });
57 };


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.253.62