body-parser

Node.js body-parsing middleware that turns raw HTTP request bodies into ready-to-use req.body objects.

Library
npm
v2.3.0
5,499 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
82 /100 Excellent
Development Activity 72
Maintenance 80
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 88
Code Quality 90
Innovation 90
Learning Curve 85

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

PHP
82%
Other

Akaunting

Invoicing Finance

10,149

Open-source online accounting for small businesses and freelancers — invoices, expenses, and reporting without monthly fees or vendor lock-in.

View details
98
Repo Health
73
Technical
63
Dependency
Built with
PHP 82%
Blade 13%
Updated 5 days ago
JavaScript
95%
MIT

AnythingLLM

AI Assistants · Automation · Developer Tools

66,533

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript 95%
Updated 6 days ago
TypeScript
49%
MPL 2.0

Artillery

Developer Tools · Devops

9,083

Cloud-scale load testing and functional testing for APIs, WebSockets, gRPC, and headless browsers, distributed across AWS Lambda or Fargate with zero infrastructure to manage.

View details
89
Repo Health
73
Technical
68
Dependency
Built with
TypeScript 49%
JavaScript 48%
Updated 1 weeks ago
Rust
67%
MIT

Bun

Developer Tools

96,068

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 5 days ago
TypeScript
96%
Other

Cal.diy

Scheduling

48,697

The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.

View details
91
Repo Health
86
Technical
65
Dependency
Built with
TypeScript 96%
Updated 6 days ago
TypeScript
96%
Other

CapRover

Developer Tools · Devops · Hosting Control Panel

15,173

Deploy any app, database, or website to your own server in minutes—no Docker or Linux expertise required.

View details
87
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,063

Open-source reporting platform to build live dashboards from SQL, NoSQL, APIs, and SaaS tools with an AI assistant that creates charts from natural language.

View details
90
Repo Health
83
Technical
64
Dependency
Built with
JavaScript 99%
Updated 1 weeks ago
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,650

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
67
Repo Health
76
Technical
62
Dependency
Built with
JavaScript 90%
Updated 3 weeks ago
JavaScript
83%
Other

Countly

Analytics · Marketing

5,908

Privacy-first, self-hosted analytics and customer engagement platform with full data ownership, GDPR compliance, and AI-powered insights across mobile, web, desktop, and IoT.

View details
96
Repo Health
82
Technical
65
Dependency
Built with
JavaScript 83%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers