Albert Remalin Raja
Albert Remalin Raja

Reputation: 45

getting req.params is showing undefined

I need product id that's _id from my mongo document but when I consoled req.params.id it is showing undefined to my /shop page and I'm following mvc format

// get request://
router.get("/shop/:id",userController.shopPage)

//route://

 getProductPage: (req, res) => {
    try{
      let proId = req.params.id;
      console.log(proId)
      productHelpers
    .getProduct(proId)
    .then((products) => {
     
      res.render("user/view-product",{products}); })}
      catch(error){

      }

//get Product//

  getProduct: (proId) => {
    console.log(proId)
    return new Promise((resolve, reject) => {
      try {
        db.products.find({_id:proId}).then((products) => {
          resolve(products);
        });
      } catch (error) {
        console.log(error);
      }
    });
  },

Upvotes: 0

Views: 26

Answers (0)

Related Questions