Kane Hooper
Kane Hooper

Reputation: 1909

Do body-parser json() and urlencoded() functions replace express json() and urlencoded() functions?

The express framework comes with the express functions express.json() and express.urlencoded().

We have the body-parser library, which appears to do the same functions.

My question is, does body-parser replace express.json() and express.urlencoded()?

Does it handle creating the req.body differently to the built in Express functions?

Upvotes: 2

Views: 400

Answers (1)

Bob Hensley
Bob Hensley

Reputation: 459

The body-parser package existed as Express middlewere until Express 4.0. At that point it was removed from the Express bundle, but people still relied on it. So around 4.1 Express brought it back but integrated it into the framework.

So yes, it’s effectively a direct replacement as these functions are directly based on body-parser. As such, they’re essentially synonymous. The Express team actually maintains body-parser.

Upvotes: 6

Related Questions