The search products API will take a GET request at /api/products?search=value&category=value, with query parameters in the URL to query the Product collection with provided search text and category values.
mern-marketplace/server/routes/product.routes.js:
router.route('/api/products') .get(productCtrl.list)
The list controller method will first process the query parameters in the request, then find products in the given category, if any, with names that partially match with the provided search text.
mern-marketplace/server/controllers/product.controller.js:
const list = (req, res) => { const query = {} if(req.query.search) query.name = {'$regex': req.query.search, '$options': "i"} if(req.query.category && req.query.category ...