body-parser
Node.js body parsing middleware — populate `req.body` from JSON, urlencoded, text, and raw payloads.
body-parser
ExpressNode.js body parsing middleware — populate `req.body` from JSON, urlencoded, text, and raw payloads.
Fit
Bundle (gzip)
217.6 kB
525.2 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Incoming HTTP request bodies arrive as raw streams. Reading, buffering, and parsing them into usable objects — while enforcing size limits and content types — is repetitive boilerplate in every Express handler.
What It Does
body-parser provides middleware that parses request bodies before your handlers run, exposing the result on req.body. It supports JSON, URL-encoded, raw, and text parsers with configurable limits, and is maintained by the Express team.
Installation
npm install body-parserUsage Example
import express from "express";
import bodyParser from "body-parser";
const app = express();
app.use(bodyParser.json({ limit: "1mb" }));
app.post("/users", (req, res) => {
res.json({ received: req.body });
});
app.listen(3000);Related packages
HTTP response compression middleware for Express — gzip/deflate responses to reduce bandwidth and improve load times.
cookie-parserExpressCookie parsing middleware for Express — parse Cookie headers into `req.cookies` and support signed cookies for tamper detection.
corsExpressCORS middleware for Express — configure cross-origin resource sharing with a single line of code.
express-async-errorsExpressSimplify Express error handling by automatically passing thrown errors to `next()`.
express-fileuploadExpressSimple Express middleware for handling `multipart/form-data` file uploads, built on Busboy.