I need to grab the rawBody (buffer) for a POST request, but I only need to do this on a single route in my application.
Currently, I'm using the following in my main app.js
:
app.use(bodyParser.json({ verify: function(req, res, buf) { req.rawBody = buf; }}));
This works, but it is sending the buffer for every route. This is undesirable because it uses twice the RAM for every request in my app.
How can I instead obtain the rawBody on the single route I need it for?
Typically, you'd create that single route and inline the middleware:
Followed by the "normal" setup:
Instead of abusing
bodyParser.json()
, you could also consider usingbodyParser.raw()
.