Reputation: 138
I'm a junior developer in Node.js. I've been importing "body-parser" for Express apps, but I recently discovered that Express has built-in middleware based on body-parser since v4.16.0.
I did RTFM for body-parser and Express, but the documentation looks pretty much the same to me. Hoping more experienced devs can offer an opinion:
Upvotes: 4
Views: 7608
Reputation: 847
express.json is literally body-parser. In the code of Express you can find this code (lib/express.js):
var bodyParser = require('body-parser')
// …
exports.json = bodyParser.json
Link: github/express
So it doesn't matter which one use for parsing
Upvotes: -1
Reputation: 542
The reason this is separate is because express.js used NOT to have any body parsing functions. That was added in V4.16+
If you are running a later version, you technically no longer need body-parser.
See https://medium.com/@mmajdanski/express-body-parser-and-why-may-not-need-it-335803cd048c
also see https://codewithhugo.com/parse-express-json-form-body/
Upvotes: 5