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:

  1. Retrieves all products from MongoDB using Mongoose.
  2. Passes them to an EJS view called products.ejs.
  3. 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.