question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

urlencoded not passing body to next middleware, but do to final controller

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
UlisesGasconcommented, Aug 5, 2020

Glad to hear that @marik22312! Thanks for provide the details and close the issue 👍

1reaction
marik22312commented, Aug 5, 2020

@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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found