Open mahendra785 opened 3 weeks ago
Create a route that returns the details of all businesses from the database. This will allow you to display business information on the website.
Express Route Handler Example:
const express = require('express');
const router = express.Router();
const Business = require('../models/businessModel'); // Assuming the schema is in `models/businessModel.js`
// GET route to fetch all businesses
router.get('/businesses', async (req, res) => {
try {
// 1. Fetch all businesses from the database
const businesses = await Business.find();
// 2. Return the businesses in the response
res.status(200).json(businesses);
} catch (error) {
// 3. Handle any errors (e.g., database issues)
res.status(500).json({ error: "Server error. Please try again later." });
}
});
module.exports = router;
Make a route which returns the details of all the businesses in the database, so that we can display it on the website.