April 2020
Intermediate to advanced
716 pages
18h 55m
English
The API endpoint to fetch all the users is declared in the following route.
mern-skeleton/server/routes/user.routes.js:
router.route('/api/users').get(userCtrl.list)
When the Express app gets a GET request at '/api/users', it executes the list controller function.
mern-skeleton/server/controllers/user.controller.js:
const list = async (req, res) => { try { let users = await User.find().select('name email updated created') res.json(users) } catch (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err) }) }}
The list controller function finds all the users from the database, populates only the name, email, created, and updated fields in the resulting user list, and then returns this list of users as ...
Read now
Unlock full access