I tried but it doesn't work any idea?
this is my code:
res.get("/signin", function(req, res) {
res.render("signin")
console.log(req.body)
}
when it shows undefined
and if I use body-parser it doesn't log when submitted instead it logs {}
to the console
CodePudding user response:
Generally speaking — there are some exceptions but not when the client is a browser — you will not get a request body on a GET request.
If you are submitting a <form>
then you need to make a POST request to get a body.
- Set the
method
attribute of the<form>
- Configure express with a
.post()
route and not a.get()
route.