After reading about both i still can't wrap my head about it, could be language differences bu please help clarify.
express.urlencoded()
Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.
And
and body-parser
middleware
Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
i understand that express.urlencoded
is based on Nodejs body-parser
.
and both pages,
https://expressjs.com/en/api.html#express.urlencoded
and
https://expressjs.com/en/resources/middleware/body-parser.html
even say the same warning note:
As req.body’s shape is based on user-controlled input, all properties and values in this object are untrusted and should be validated before trusting. For example, req.body.foo.toString() may fail in multiple ways, for example foo may not be there or may not be a string, and toString may not be a function and instead a string or other user-input.
but eventually both give me a req.body
with params sent in requests body object. so why should i use body-parser (which i have to install separatly) instead of always using express.urlencoded()
I know this isn't a code problem but i thank in advance for anyone who can list up to the main differences.
body-parser
there is still a change of dependencies fails (like what i'm experiencing with PassportJS which after investigating seems it misses the body parser even though i have theurlencoded
middleware on. could be?) – Peabody