'In express delete working in res object but it should be req and if it work why it is working
I am making simple SQL and express connections and doing an insert, update, and delete. Insert and update is working fine but when I started to delete using req.body I getting undefined in the body part
app.delete('/empdelete',function(res,req)
{
console.log(req);
db.query('delete from product.employee where id = ?', [req.body.id], function (err,rows){
console.log(err);
console.log(rows);
req.redirect('/');
});
});
and when i change to req to res it work fine so why it work on res it should be req
app.delete('/empdelete',function(res,req)
{
console.log(res);
db.query('delete from product.employee where id = ?', [res.body.id], function (err,rows){
console.log(err);
console.log(rows);
req.redirect('/');
});
});
Solution 1:[1]
It is because your sequence of args in the callback is incorrect. The syntax should be as:
app.delete('/:route',function(req,res)
{
console.log(req.body);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pranay Tripathi |
