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 install body-parser
yarn add body-parser
pnpm add body-parser
Import
import bodyParser from 'body-parser';
Quick Example
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
| Package | body-parser |
| Category | HTTP |
| Weekly Downloads | 15M+ |
| License | MIT |
| Install | npm install body-parser |
Related Packages
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
Multer is a Node.js middleware for handling multipart/form-data, which is primarily used for uploadi…
CORS (Cross-Origin Resource Sharing) is an Express/Connect middleware that enables cross-origin requ…
Helmet helps secure Express.js applications by setting various HTTP response headers that protect ag…
Cookie-parser is an Express middleware that parses Cookie header values and populates req.cookies wi…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.