body-parser
Express and Connect middleware that parses JSON, urlencoded, raw, and text request bodies onto req.body.
Official Documentation ↗v2.4.0. Check the official docs for the latest API surface.Installation
npm install body-parserMethods
No methods match this filter.
body-parser reads the request stream, decodes it according to Content-Type, and assigns the result to req.body.
Key Features
- Independent parsers for JSON, urlencoded, raw, and text
- Configurable size limits, strictness, and inflate behavior
- Raw parser preserves bytes for signature verification
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://expressjs.com/en/resources/middleware/body-parser.html · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:28.676Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- The various errors returned by this module are described in the errors section . (https://expressjs.com/en/resources/middleware/body-parser.html)
- Errors The middlewares provided by this module create errors using the http-errors module . (https://expressjs.com/en/resources/middleware/body-parser.html)
- The following are the common errors created, though any error can come through for various reasons. (https://expressjs.com/en/resources/middleware/body-parser.html)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://expressjs.com/en/resources/middleware/body-parser.html · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:28.676Z.
- Note As req.body ’s shape is based on user-controlled input, all properties and values in this object are untrusted and should be validated before trusting. (https://expressjs.com/en/resources/middleware/body-parser.html)
- The OpenJS Foundation AI Coding Assistants Policy Bylaws Code of Conduct Cookie Policy Privacy Policy Security Policy Terms of Use Trademark List Trademark Policy Kawaii? (https://expressjs.com/en/resources/middleware/body-parser.html)
FAQ
- Is body-parser still needed with Express 4.16+?
- No for JSON and urlencoded. Express bundles express.json() and express.urlencoded(), which behave almost identically. Use body-parser for raw or text bodies.
- How do I verify webhook signatures?
- Use bodyParser.raw() so the exact bytes are preserved, compute the HMAC over req.body, and only then parse the payload as JSON.
- Why does req.body come back empty?
- The Content-Type header must match the parser. A mismatched type leaves req.body undefined, so check it before reading fields.
Report a problem with this API docOpens a pre-filled issue on GitHub.