express.json vs bodyParser.json

express, json

Solution

Earlier versions of Express used to have a lot of middleware bundled with it. bodyParser was one of the middleware that came with it. When Express 4.0 was released they decided to remove the bundled middleware from Express and make them separate packages instead. The syntax then changed from `app.use(express.json())` to `app.use(bodyParser.json())` after installing the bodyParser module.

bodyParser was added back to Express in release 4.16.0, because people wanted it bundled with Express like before. That means you don't have to use `bodyParser.json()` anymore if you are on the latest release. You can use `express.json()` instead.

The release history for 4.16.0 is here for those who are interested, and the pull request is here.

Problem

I'm writing a relatively new app and was wondering which I should use: ``` express.json() ``` or ``` bodyParser.json() ``` Can I assume they do the same thing. I would like to just use `express.json()` as it is built in already.

Original source