June 2014
Intermediate to advanced
696 pages
38h 52m
English
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 };
Read now
Unlock full access