I'm working with express to set up an API, and I came across this line of code: app.use(express.json( { extended: false } ));
I've seen the documentation from express, but I didn't find this method, is the documentation lacking or am I missing something?
The express. urlencoded() function is a built-in middleware function in Express. It parses incoming requests with urlencoded payloads and is based on body-parser.
urlencoded() is a built-in middleware in Express. js. The main objective of this method is to parse the incoming request with urlencoded payloads and is based upon the body-parser. This method returns the middleware that parses all the urlencoded bodies.
json() is a built-in middleware function in Express. This method is used to parse the incoming requests with JSON payloads and is based upon the bodyparser. This method returns the middleware that only parses JSON and only looks at the requests where the content-type header matches the type option.
The arguments available to an Express. js route handler function are: req - the request object. res - the response object.
Answers come from looking at the actual Express and body-parser code...
If you go look at the Express code for the express.json()
method here, you can see that it is a direct pass-through of the .json()
method from the body-parser module.
// from express.js
exports.json = bodyParser.json;
So, if you then go look at the body-parser doc, there is nothing there for the extended
option for the body-parser.json()
middleware.
As you have discovered, the extended
option is documented for the body-parser.urlencoded()
middleware. But, since that is different than the .json()
middleware method, it appears that this code is mistaken to be using the extended
option with the .json()
middleware.
If you go look at the code for the body-parser.json()
middleware, you will find no references at all to the extended
option in the code.
So, it appears to be an option that is mistakenly passed in the code you show and is subsequently ignored by the express/body-parser json middleware.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With