June 2014
Intermediate to advanced
696 pages
38h 52m
English
The code in Listing 26.8 implements the deleteUser route. This route finds the user in the MongoDB database and then calls the remove() method on the User object to remove the user from the database. Also notice that req.session.destroy() is called to remove the session because the user no longer exists.
Listing 26.8 users_controller.js-deleteUser: Implementing the route to delete users for the Express server
73 exports.deleteUser = function(req, res){74 User.findOne({ _id: req.session.user })75 .exec(function(err, user) {76 if(user){77 user.remove(function(err){78 if (err){79 req.session.msg = err;80 }81 req.session.destroy(function(){ ...
Read now
Unlock full access