Ask coding questions

← Back to all posts
req.body doesn't seem to be working.

I don't think I am able to access req.body. I've tried everything I can think of, but I'm really new to express, so there's probably something I missed.

P.S. Ignore the extreme insecurity of the app. That isn't really the point.

Answered by HackermonDev (2076) [earned 5 cycles]
View Answer
HackermonDev (2076)

It looks like you are using app.get. Request bodies only work on and PUT requests.


@HackermonDev I would have used a POST request anyway, but when I change it to, it says cannot GET / (I changed my views/home.ejs form to do post as well).


@HackermonDev Do I need to make an and an app.get? Or is there an equivalent to the request object for GET?


@HackermonDev I made both an and an app.get, and the message that I sent shows up in the database now, but not on the website.