#express js #node #node js #post #forms

How to get form data in post request in Express JS - Node JS

if you are starting new with Node JS, you will probably face this problem, while submitting the form to a post URL.

The problem you will face is getting a empty req.body in-spite of sending the form properly. To resolve this issue, you have make two change in your current system.

Add the following to the form element

enctype="application/x-www-form-urlencoded"

Though, if you do not add this it will still work as this is the default for a form.

The second thing, in your index.js in root add the following lines to unable the form.

app.use(express.urlencoded({
    extended: true
}));

This is it, now you will be able to receive the form data in req.body

if you are facing the same issue for the JSON inputs in your API calls, please check the link here to unable it.