The following is the code for posting a product using an angular service. Here I'm passing the product as the body
addProduct(product): Observable<any> {
return this.http.post<Observable<any>>(
`http://localhost:4401/api/products`,
{
product,
}
);
}
But when I try to access it inside my express server I am getting an undefined.
app.post("/api/products", async (req, res) => {
console.log("req :", req.body);
});
Other verbs like GET
, DELETE
is working fine.
Also the following is also working fine:
app.get("/api/products/:id", async (req, res) => {
try {
const responseData = await db.get(req.query.id);
res.json({ product: responseData });
} catch (e) {
console.log(e);
}
});
But the params inside the POST
verbe is not getting received inside the express server.