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.
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 };