req.body returns a Buffer
See original GitHub issueFor some reason in some version change (apologize I don’t know from which version this started, but sometime after the switch from AWS to Vendia as the maintainer), req.body now returns a Buffer.
"body":{"type":"Buffer","data":[123,34,119,104,97,116,116,104,101,34,58,34,105,116,39,115,32,104,101,114,101,49,34,125]}}
Is this intended? This is even after using bodyParser.json() as middleware.
I have found that I can use
const { event, context } = getCurrentInvoke();
console.log(event.body)
That seems to give me a better response but takes place outside the Express environment.
I’m curious as to why req.body returns a Buffer instead of a json object.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
Express 4.17 req.body is being printed as buffer
logging req.body in my express app. I end up with a buffer/string or hexadecimal of some sort when I'm expecting an JSON object....
Read more >Express body-parser middleware
Returns middleware that parses all bodies as a Buffer and only looks at requests where the Content-Type header matches the type option. This...
Read more >Request.arrayBuffer() - Web APIs - MDN Web Docs
The arrayBuffer() method of the Request interface reads the request body and returns it as a promise that resolves with an ArrayBuffer ....
Read more >5. Parse the request body using Buffer and extract ... - YouTube
In this video we will see how to parse the request body using buffer and extract the form data and save it in...
Read more >Anatomy of an HTTP Transaction
on('end', () => { body = Buffer.concat(body).toString(); // at this point, `body` has the entire request body stored in it as a ...
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
Hi guys, I hope this solution to be useful for you…
app.post(“/email”,(req, res)=>{ const jsonBodyData = req.apiGateway.event.body;
console.log(JSON.parse(jsonBodyData)); })
This is happening to us as well, 4.10.1