May 2018
Intermediate to advanced
470 pages
13h 54m
English
The API endpoint to update a single user is declared in the following route.
mern-skeleton/server/routes/user.routes.js:
router.route('/api/users/:userId').put(userCtrl.update)
When the Express app gets a PUT request at '/api/users/:userId', similar to the read, it first loads the user with the :userId param value, and then the update controller function is executed.
mern-skeleton/server/controllers/user.controller.js:
const update = (req, res, next) => { let user = req.profile user = _.extend(user, req.body) user.updated = Date.now() user.save((err) => { if (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err) }) } user.hashed_password = undefined user.salt = undefined res.json(user) })}
The update function ...
Read now
Unlock full access