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.

req.body returns a Buffer

See original GitHub issue

For 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

1reaction
manuelhonoredesousacommented, Dec 15, 2022

Hi guys, I hope this solution to be useful for you…

You can get your body data like that…

app.post(“/email”,(req, res)=>{ const jsonBodyData = req.apiGateway.event.body;
console.log(JSON.parse(jsonBodyData)); })

0reactions
rfinkcommented, Dec 12, 2022

This is happening to us as well, 4.10.1

Read more comments on GitHub >

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

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