Skip to content
Advertisement

the id of cart shows null in controller but i m sure i m sending it NODE JS

I m sending the id of the product from this view (I m using express and mongoose db)

JavaScript

I m sure it is not null here

then I have this middleware to receive it

JavaScript

and here is the function post Cart

JavaScript

When I first receive it in the postcard function I made a log and it gives me the log console

JavaScript

I tried wrapping the id with ObjectId of mongoose then it shows me this message

JavaScript

error :

JavaScript

product: in database :

JavaScript

Advertisement

Answer

Replace const prodId = req.params.id; with const prodId = req.body.id; and write

JavaScript

The express.urlcoded middleware is needed to fill the req.body.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement