DEV Community

Discussion on: You probably don't need body-parser in your Express apps

Collapse
 
sumanthyedoti profile image
Sumanth Yedoti

I think, express.json() is to parse header body which is json. Body parser is also to parse form data. Please correct me if im wrong.

Collapse
 
taylorbeeston profile image
Taylor Beeston

As per the Express docs

This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser.

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred.