May 2018
Intermediate to advanced
470 pages
13h 54m
English
In the backend, we will add a route in server/routes/shop.routes.js to retrieve all the shops stored in the database when the server receives a GET request at '/api/shops':
router.route('/api/shops') .get(shopCtrl.list)
The list controller method in shop.controller.js will query the Shop collection in the database to return all the shops.
mern-marketplace/server/controllers/shop.controller.js:
const list = (req, res) => { Shop.find((err, shops) => { if (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err) }) } res.json(shops) })}
Read now
Unlock full access