#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.


mohammed-samgan-khan

Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.