body-parser
Node.js body-parsing middleware that turns raw HTTP request bodies into ready-to-use req.body objects.
Repository Health
Technical Analysis
body-parser is the canonical Node.js middleware for reading and parsing incoming HTTP request bodies before they reach your route handlers. Maintained under the Express organization, it exposes four focused parsers — JSON, URL-encoded, raw, and text — each of which inspects the request’s Content-Type, buffers the body with sensible size limits, transparently inflates gzip/brotli/deflate encodings, and populates req.body with the decoded result.
It is deliberately narrow in scope: it does not handle multipart uploads, and each parser is a small, composable factory you mount only where you need it. That focus, combined with battle-tested charset handling and robust error normalization, has made body-parser a foundational dependency across the Node.js ecosystem with over 100 million weekly downloads.
What You Get
- Four dedicated parsers — json(), urlencoded(), raw(), and text() — each importable individually or from the main module.
- Automatic decompression of gzip, brotli, and deflate request bodies before parsing.
- Configurable body-size limits, charset validation, and a verify hook for rejecting bodies before they are parsed.
- Content-Type negotiation via the type-is library, so parsers activate only for matching requests.
- Normalized, HTTP-status-carrying errors (via http-errors) that integrate cleanly with Express error handling.
Common Use Cases
- Reading JSON API payloads into req.body in an Express or Connect application.
- Handling HTML form submissions sent as application/x-www-form-urlencoded.
- Capturing raw Buffer bodies for webhook signature verification.
- Accepting plain-text payloads on specific endpoints.
Under The Hood
Architecture
The public surface is defined in index.js, which exports four parser factories (json, raw, text, urlencoded) and a deprecated generic that now throws to steer users toward the individual middleware. Each parser module in lib/types/ follows the same shape: it calls normalizeOptions() from lib/utils.js to resolve the content type, byte limit (via the bytes library), inflate flag, default charset, and a shouldParse type-checker built on type-is, then returns an Express-style (req, res, next) function that delegates the actual work to the shared lib/read.js. read.js is the engine: it short-circuits already-finished or body-less requests, uses raw-body to buffer the stream under the size limit, pipes through Node’s zlib for gzip/brotli/deflate inflation, decodes bytes with iconv-lite, and finally invokes the parser-specific parse function before assigning req.body.
Tech Stack
A CommonJS module targeting Node.js >= 18. Its runtime dependencies are all small, single-purpose Express-org libraries: bytes (limit parsing), content-type, debug, http-errors (status-carrying errors), iconv-lite (charset decoding), on-finished, qs (extended URL-encoded parsing), raw-body (stream buffering), and type-is (Content-Type matching). Development uses ESLint with the Standard config, Mocha for tests, nyc for coverage, and supertest for HTTP-level assertions.
Code Quality
The codebase is compact and heavily tested — roughly 275 it() cases spread across dedicated suites for each parser plus utils, run with --check-leaks and coverage reporting. Source files are strict-mode, thoroughly JSDoc-annotated, and show careful attention to edge cases: the JSON parser reconstructs native-looking SyntaxError messages for strict-mode violations, normalizes error objects to drop extraneous properties, and special-cases empty bodies. Options are validated eagerly with clear TypeError messages.
API Design
The developer experience is deliberately minimal and consistent. Every parser is a factory taking the same core option keys (inflate, limit, type, verify, plus parser-specific extras like strict or extended), so learning one parser transfers to all four. Parsers can be imported individually (require('body-parser/json')) to keep bundles lean, and the README documents every option and every error condition exhaustively.
Used by 36 apps in this directory
overleaf
Collaboration · Productivity
Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.
Plasmic
CMS · Design Tools · Low Code Platforms
The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.
Rocket.Chat
Team Chat
The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.
Silex
Design Tools · No Code Platforms
Free, open-source visual website builder that exports clean HTML/CSS — no lock-in, no subscription, host anywhere
SillyTavern
AI Assistants
The power-user LLM frontend that unifies dozens of AI backends with a rich scripting engine, immersive Visual Novel mode, and a thriving extension ecosystem.
swagger-ui
Developer Tools
Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.
Termix
Devops
Manage all your servers — SSH terminals, remote desktops, file transfers, and Docker containers — from a single self-hosted browser interface.
TinaCMS
CMS
An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.
Wiki.js
Collaboration · Knowledge Management
A modern, self-hosted wiki platform built on Node.js with a rich plugin ecosystem for authentication, search, storage, and rendering that adapts to any team's infrastructure.