🌐
HTTP15M+/wkMIT

body-parser

Body-parser is a Node.js body parsing middleware that extracts the body portion of incoming HTTP requests and makes it available under req.body. The middleware

Installation

npm
npm install body-parser
yarn
yarn add body-parser
pnpm
pnpm add body-parser

Import

ESM
import bodyParser from 'body-parser';

Quick Example

usage
import express from 'express';
import bodyParser from 'body-parser';

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/data', (req, res) => {
  res.json(req.body);
});

About body-parser

Body-parser is a Node.js body parsing middleware that extracts the body portion of incoming HTTP requests and makes it available under req.body. The middleware supports parsing JSON payloads, URL-encoded form data, raw binary buffers, and plain text bodies. Each parser can be configured with size limits to prevent denial-of-service attacks from oversized request bodies, custom content type matching, and encoding options. The JSON parser handles Content-Type application/json, the urlencoded parser handles application/x-www-form-urlencoded (the default format for HTML form submissions), and the raw and text parsers handle arbitrary binary and text content types respectively. While Express 4.16+ includes built-in body parsing via express.json() and express.urlencoded() (which are actually re-exports of body-parser), the standalone body-parser package is still widely used with other frameworks and in projects that need the raw or text parsers. Body-parser was originally part of Express's core and was extracted into a separate module as part of Express 4's modularization effort.

Quick Facts

Packagebody-parser
CategoryHTTP
Weekly Downloads15M+
LicenseMIT
Installnpm install body-parser

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.