body-parser

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

Library
npm
v2.4.0
5,500 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
86 /100 Excellent
Development Activity 84
Maintenance 84
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

TypeScript
62%
EPL-2.0

Huly Platform

Collaboration · Project Management · Team Chat

27,978

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript 62%
Svelte 34%
Updated 2 days ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,980

The superpowered headless CMS for developers built with GraphQL and React

View details
92
Repo Health
81
Technical
64
Dependency
Built with
TypeScript 99%
Updated 2 days ago
TypeScript
88%
Apache 2.0

Medplum

Authentication · Databases · Developer Tools

2,760

An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.

View details
93
Repo Health
90
Technical
71
Dependency
Built with
TypeScript 88%
Updated yesterday
TypeScript
97%
Other

nango

Authentication · Automation · Developer Tools

12,963

Build product integrations with AI using 800+ APIs — auth, proxy, and TypeScript functions on production-grade infrastructure.

View details
94
Repo Health
85
Technical
67
Dependency
Built with
TypeScript 97%
Updated 2 days ago
TypeScript
49%
MIT

Nginx Proxy Manager

Developer Tools · Networking · Security

34,517

Manage Nginx reverse proxies and free Let's Encrypt SSL through a beautiful web interface — no Nginx expertise required.

View details
92
Repo Health
77
Technical
72
Dependency
Built with
TypeScript 49%
JavaScript 47%
Updated 5 days ago
JavaScript
88%
GPL 3.0

NodeBB

Community

15,242

Modern Node.js forum software with real-time WebSockets, multi-database support, and a plugin ecosystem — the community platform built for the open web and the Fediverse.

View details
97
Repo Health
78
Technical
70
Dependency
Built with
JavaScript 88%
Go Template 11%
Updated yesterday
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated yesterday
TypeScript
26%
AGPL 3.0

Omnivore

Bookmarks Archiving · Knowledge Management · Note Taking

16,356

Self-hosted read-it-later platform with highlights, newsletters, PDFs, and seamless Obsidian and Logseq integration.

View details
90
Repo Health
74
Technical
65
Dependency
Built with
TypeScript 26%
JavaScript 24%
HTML 20%
Updated 2 days ago
Go
36%

OpenPanel

Devops · Hosting Control Panel

764

Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.

View details
87
Repo Health
75
Technical
63
Dependency
Built with
Go 36%
HTML 30%
TypeScript 24%
Updated 2 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