Skip to content
Advertisement

Get buffer from post body in Expressjs

I am making an express application that handles post data. Because the request body could be any content type and/or binary, I would like req.body to be a Buffer. So what should I use to get a Buffer that represents the request body? Here is my code:

JavaScript

Advertisement

Answer

body-parser can help achieve this, code example would be as,

JavaScript

See more details about Raw body parser and default options needs to be supplied – bodyParser.raw([options])

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement