Body parser with Express.js
To read HTTP POST data we need to use body-parser. Body-parser is a middleware module. It was a part of Express.js before. Now the middleware has to be installed seperately. In Express.js we can get data without using body-parser. It is a piece of express middleware that reads form’s input and access it through req.body after storing it as javascript object. You can read any data inside HTTP request like headers req.headers you can read body of http packet as re.body. The body-parser extract the whole body portion of the incoming request stream and exposes it on req.body. The module i.e the body-parser parses the JSON, buffer, string and URL encoded data submitted using HTTP POST request. You can install body-parser using NPM as given below.
npm install body-parser –save
In the Express.js 4.16.0 version the body-parser middle-ware is bundled with it.
Comments
0 comments
Please Sign in or Create an account to Post Comments