SP25 BSCS Q4
Question:
You are building a product listing application using Express, EJS, and Mongoose. Consider the following Mongoose model:
models/Product.js
const mongoose = require("mongoose");
const productSchema = new mongoose.Schema({
name: String,
price: Number,
});
module.exports = mongoose.model("Product", productSchema);
Task:
Implement an Express route at /products that:
- Retrieves all products from MongoDB using Mongoose.
- Passes them to an EJS view called
products.ejs. - The EJS file should render a list of product names and their prices in an HTML table.
Part A:
Write the code for the Express route.
Part B:
Write the EJS code for products.ejs that displays the product data in an HTML table.