Reading

The API endpoint to read a single user's data is declared in the following route.

mern-skeleton/server/routes/user.routes.js:

router.route('/api/users/:userId').get(userCtrl.read)

When the Express app gets a GET request at '/api/users/:userId', it executes the userByID controller function to load the user by the userId value in the param, and then the read controller function.

mern-skeleton/server/controllers/user.controller.js:

const read = (req, res) => {  req.profile.hashed_password = undefined  req.profile.salt = undefined  return res.json(req.profile)}

The read function retrieves the user details from req.profile and removes sensitive information, such as the hashed_password and salt values, before sending the user object in the ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.