npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@prexjs/body-parser

v1.0.0

Published

Node.js body parsing middleware for JSON, URL-encoded, raw buffer, and text HTTP requests.

Readme

@prexjs/body-parser

Node.js body parsing middleware for JSON, URL-encoded, raw buffer, and text HTTP requests.

npm version npm downloads License: MIT TypeScript

@prexjs/body-parser parses incoming request bodies in standard HTTP middleware pipelines before handlers receive them, populating req.body with parsed representations. It provides dedicated parsers for JSON, form URL-encoded data, raw binary buffers, and plain text.

Features

  • JSON Parser (json): Parses JSON payloads with customizable revivers, strict typing mode, and size limits.
  • URL-Encoded Parser (urlencoded): Parses UTF-8 URL-encoded form data with customizable depth and parameter limits.
  • Raw Body Parser (raw): Parses incoming payloads into a binary Buffer with strict Content-Type checks.
  • Text Parser (text): Parses request streams into string bodies with customizable character set decoders.
  • Stream Inflation & Limit Control: Automatically uncompresses gzip/deflate streams and enforces byte limits.
  • Standard Middleware Contract: Integrates seamlessly with Prex, Connect, and standard Node.js HTTP servers.

Installation

Install using your preferred package manager:

# npm
npm install @prexjs/body-parser

# pnpm
pnpm add @prexjs/body-parser

# Yarn
yarn add @prexjs/body-parser

# Bun
bun add @prexjs/body-parser

Quick start

import http from 'node:http';
import bodyParser, { json, urlencoded } from '@prexjs/body-parser';

// Create JSON middleware
const parseJson = json({ limit: '1mb' });
const parseUrlencoded = urlencoded({ extended: true });

const server = http.createServer((req: any, res) => {
  parseJson(req, res, (err) => {
    if (err) {
      res.statusCode = 400;
      res.end('Bad Request: Invalid JSON');
      return;
    }

    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({ received: req.body }));
  });
});

server.listen(3000);

API

json(options?)

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option.

  • limit: Maximum request body size (default: '100kb').
  • strict: When true, only accepts arrays and objects (default: true).
  • reviver: Reviver function passed to JSON.parse.

urlencoded(options?)

Returns middleware that parses URL-encoded bodies (like HTML forms).

  • extended: Parse with advanced query-string parser when true (default: true).
  • limit: Maximum request body size (default: '100kb').
  • parameterLimit: Maximum number of parameters allowed (default: 1000).

raw(options?)

Returns middleware that parses all bodies as a Buffer.

  • limit: Maximum size (default: '100kb').
  • type: Content-Type to match (default: 'application/octet-stream').

text(options?)

Returns middleware that parses all bodies as a string.

  • limit: Maximum size (default: '100kb').
  • defaultCharset: Default character encoding if unspecified in headers (default: 'utf-8').

Compatibility

  • Node.js >= 18.0.0
  • Supports both ESM and CommonJS
  • TypeScript 5.0+

Related Packages

License

MIT