urlencoded not passing body to next middleware, but do to final controller
See original GitHub issueHi, I’ve encountered some weird behavior from the URL encoded parser… it seems that the body is not passed to my next middleware, but It’s passed to the final controller.
in example sending the following data:
name='test'
to this route:
// test.ctrl.ts
export const myController = (req: Request, res: Response, next: NextFunction) => {
console.log(req.body) // prints { name: 'test' }
}
// routes.ts
router.post('/', bodyParser.urlencoded({ extended: true }), (req, res, next) => {
console.log(req.body) //prints {}
next()
}, myController);
note that in the middleware, it prints an empty object, and in the controller, I get the body correctly…
I do not completely understand why and how this is possible… any suggestions?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Express.js req.body undefined - Stack Overflow
I read that this problem is caused by the lack of app.use(express.bodyParser()); but as you can see I call it before the routes....
Read more >Express body-parser middleware
This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.
Read more >Understanding Body Parser In Express JS - Simplilearn
It provides four express middleware for parsing JSON, Text, URL-encoded, and raw data sets over an HTTP request body.
Read more >Routing and Analyzing Request Data with Node.js - Manning
This article covers routing and how a few more Express.js methods allow you to send meaningful data to the user before building a...
Read more >Complete Guide to Express Middleware - Reflectoring
If the current middleware function does not end the request-response cycle, it must call next() to pass control to the next middleware function....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Glad to hear that @marik22312! Thanks for provide the details and close the issue 👍
@UlisesGascon hey, yes! The issue was between the seat and the screen… I had a multer Middleware which also parsed the body… So naturally, body parser couldn’t get the body from a formData request…
Closing the issue…