Ask coding questions

← Back to all posts
req.body doesn't seem to be working.
KENNETHTRIPP (52)

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
Comments
hotnewtop
HackermonDev (2076)

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

KENNETHTRIPP (52)

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

KENNETHTRIPP (52)

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

KENNETHTRIPP (52)

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