Categories
JavaScript Answers

How to get raw request body using Express with Node.js?

Spread the love

To get raw request body using Express with Node.js, we use the req.body property.

For instance, we write

const bodyParser = require("body-parser");
app.use(bodyParser.raw(options));

app.get(path, (req, res) => {
  console.log(req.body);
  //...
});

to call app.get to create a route handler for the path path.

Then we get the request body with req.body.

req.body is a buffer object.

We use the bodyParser.raw middleware to parse the request body into a buffer.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *