explaingit

expressjs/body-parser

5,500JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A small Node.js library used with Express web servers to automatically decode incoming request data, JSON, form submissions, raw binary, or plain text, and make it available as a JavaScript object.

Mindmap

mindmap
  root((repo))
    What it does
      Decodes raw request bytes
      Attaches to req.body
      Works with Express
    Supported Formats
      JSON
      URL-encoded forms
      Raw binary
      Plain text
    Configuration
      Size limits
      Encoding settings
      Compression support
      Custom verification
    Security
      Treat req.body as untrusted
      Validate before use
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Parse JSON sent by a mobile app or frontend to your Express API so you can read it as a normal JavaScript object

USE CASE 2

Handle HTML form submissions in an Express app by decoding URL-encoded form data automatically

USE CASE 3

Add payload size limits to your Express server to reject oversized requests before they reach your app logic

Tech stack

JavaScriptNode.jsExpress

Getting it running

Difficulty · easy Time to first run · 5min

Install via npm. Does not handle file uploads or multipart forms, use multer or busboy for those cases.

No explicit license mentioned in the explanation.

In plain English

When a web server receives data sent by a browser or app, that data arrives as raw bytes. Before a Node.js server can do anything useful with it, the data needs to be decoded into a usable format. body-parser is a small library that sits in the middle of that process and handles the decoding automatically. It is part of the Express.js ecosystem, the most widely used web framework for Node.js. The library supports four formats. JSON parsing reads data structured as key-value pairs, which is the most common format for modern APIs. URL-encoded parsing handles form submissions from HTML pages. Raw parsing keeps the data as-is in binary form. Text parsing reads the body as a plain string. Each parser is available separately, so a project can include only the formats it needs. Once body-parser processes an incoming request, the decoded data is attached to the request object under a property called req.body, where the rest of the application can read it. Each parser can be configured with options: a size limit to reject oversized payloads, encoding settings, whether to accept compressed data, and a custom verification function for extra checks before parsing begins. The README notes an important security consideration: because req.body contains data that came from the user, every property in it should be treated as untrusted and validated before use. A caller cannot assume that a field exists, has the expected type, or is safe to call methods on. The library does not handle file uploads or multipart form data, which have their own complexity. For those use cases, the README points to alternatives such as multer, busboy, and formidable. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Show me how to add body-parser to an Express app so I can read JSON data posted from a React frontend using req.body.
Prompt 2
How do I configure body-parser to reject requests larger than 1MB and return a proper error response in Express?
Prompt 3
I need to parse both JSON and URL-encoded form data in the same Express app. How do I set up multiple body-parser middleware for both formats?
Prompt 4
What security checks should I add after reading req.body with body-parser before using the data in my database query?
Open on GitHub → Explain another repo

← expressjs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.