I would like to get the raw request body in one of my middlewares in my Express app. There are a few posts on Stackoverflow that show how to do this (e.g. Node.js - get raw request body using Express or Writing express middleware to get raw request body before body-parser), but:
- They use body-parser, which I believe is built-in with the new Express version, so am not sure how to use it in this case
- They extract the raw request in
app.use()
, which means that all routes would extract the raw request, whereas I only want to extract it in one route (more specifically, in an independent middleware that's buried deep in my code rather than inapp.js
, to which I want to be able to just pass thereq
element and extract its raw body there).
Any advice on the best way to do this?