concept Mongoose method in category angular

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.
This list seems like a lot of things to do, but fortunately, everything is easy; you’ve already done the hard work by creating the Mongoose methods. Now, you need to tie everything together. The following listing shows the complete code for the register controller.
Listing 11.12. register controller for the API
const register = (req, res) => { if (!req.body.name || !req.body.email || !req.body.password) { #1 return res #1 .status(400) #1 .json({"message": "All fields required"}); #1 } #1 const user = new User(); #2 user.name = req.body.name; #2 user.email = req.body.email; #2 user.setPassword(req.body.password); #3 user.save((err) => { #4 if (err) { res .status(404) .json(err); } else { const token = user.generateJwt(); #5 res #5 .status(200) #5 .json({token}); #5 } }); }; module.exports = { register };In this piece of code, there’s nothing particularly new or complex, but it highlights the power of Mongoose methods. This registration controller could have been complex had everything been written inline, which would have been tempting if you’d started here instead of with Mongoose. But as it is, the controller is easy to read and understand, which is what you want from your code.