Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

body-parser

Package Overview
Dependencies
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-parser

Node.js body parsing middleware

  • 1.20.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36M
increased by2.03%
Maintainers
2
Weekly downloads
 
Created

What is body-parser?

The body-parser package is a Node.js middleware that parses incoming request bodies before your handlers, available under the req.body property. It is commonly used to parse JSON, raw, text, and URL-encoded form data.

What are body-parser's main functionalities?

JSON Body Parsing

This feature allows the server to accept and parse incoming requests with JSON payloads, making the parsed data available under req.body.

const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.json());

app.post('/json', (req, res) => {
  res.send(req.body);
});

URL-Encoded Form Data Parsing

This feature is used to parse payloads from forms submitted via HTTP POST. The 'extended' option allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded forms.

const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.urlencoded({ extended: true }));

app.post('/form', (req, res) => {
  res.send(req.body);
});

Raw Body Parsing

This feature lets the server accept raw data in the request body, useful for parsing bodies that are not text-based, like binary data streams.

const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.raw({ type: 'application/vnd.custom-type' }));

app.post('/raw', (req, res) => {
  res.send(req.body);
});

Text Body Parsing

This feature allows parsing text bodies, such as plain text or HTML, from the request body.

const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.text({ type: 'text/html' }));

app.post('/text', (req, res) => {
  res.send(req.body);
});

Other packages similar to body-parser

FAQs

Package last updated on 09 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc