body-parser is Node.js middleware that parses JSON, URL-encoded, text, and raw request bodies into req.body before route handlers run. It supports size limits and optional decompression.
Overview
body-parser provides middleware for Express-style applications to parse incoming HTTP bodies before your handlers execute. Parsed data is exposed on req.body when the Content-Type matches the configured parser.
Separate factories handle JSON, raw buffers, plain text, and URL-encoded forms. Documentation warns that req.body reflects untrusted client input and should be validated before use. Multipart uploads are explicitly out of scope and left to other middleware.
Parsers can inflate gzip, brotli, deflate, and zstd encodings where supported by the Node version. Options cover charset defaults, strict JSON parsing, custom verification hooks, and configurable size limits.
The module is a focused utility for web servers rather than a standalone application, and integrates with the broader Express ecosystem.
Key features
- JSON body parsing
- URL-encoded form parsing
- Raw buffer parsing
- Plain text parsing
- Compressed body inflation
- Configurable size limits
- Content-Type matching
- Optional verify hook
Use cases
- Parsing JSON APIs
- Handling HTML forms
- Reading raw upload bytes
- Express route preprocessing