Let's try to keep it the least technical.
Suppose you submit html form data to a node-js server, i.e. You have made a request to the server. The server file will receive your request under the request object. Now, logically, if you consolidate this request object in your server file, you should see the data of your form somewhere in it, which could be extracted then, but whoa! you really don't!
So where is our data? How do we extract it, if itβs not only in my request.
A simple explanation for this is that http sends your form data into bits and pieces that are intended to be assembled as they are reached. So how would you retrieve your data.
But why not cause this pain every time manually disassembling your data for pieces and assembly. Use something called "body-parser" that will do it for you.
body-parser analyzes your request and converts it into a format from which you can easily extract the information you need.
For example, let's say you have a registration form in your interface. You fill it in and request a server to save data somewhere.
Retrieving the username and password from your request is as simple as shown below if you use body-parser.
var loginDetails = { username : request.body.username, password : request.body.password };
So body-parser analyzed your incoming request, collected pieces containing your form data, and then created this body object for you and populated it with form data.
Abzy Aug 19 '18 at 21:54 2018-08-19 21:54
source share