Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
body-parser
Advanced tools
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.
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);
});
Multer is a middleware for handling 'multipart/form-data', primarily used for uploading files. It is different from body-parser as it is specialized for file upload scenarios.
Formidable is a Node.js module for parsing form data, especially file uploads. It can handle multiple file uploads and supports file size limits, making it more feature-rich for handling forms than body-parser.
Busboy is a streaming parser for HTML form data for Node.js. It is faster and more efficient for large file uploads compared to body-parser, which does not handle file streams.
Designed for the Koa framework, koa-body is a full-featured body parser middleware. It supports multipart, urlencoded, and json request bodies and provides additional features like file uploads, making it a more comprehensive solution than body-parser for Koa applications.
Connect's body parsing middleware.
var bodyParser = require('body-parser');
var app = connect();
app.use(bodyParser());
app.use(function (req, res, next) {
console.log(req.body) // populated!
next();
})
Returns middleware that parses both json
and urlencoded
. The options
are passed to both middleware.
Returns middleware that only parses json
. The options are:
strict
- only parse objects and arrayslimit
<1mb> - maximum request body sizereviver
- passed to JSON.parse()
Returns middleware that only parses urlencoded
with the qs module. The options are:
limit
<1mb> - maximum request body sizeThe MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Node.js body parsing middleware
The npm package body-parser receives a total of 29,200,120 weekly downloads. As such, body-parser popularity was classified as popular.
We found that body-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.