
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
body-parser-yieldable
Advanced tools
Node.js body parsing middleware with yieldable-json 100% based in body-parser.
Parse incoming request bodies in a middleware before your handlers, available
under the req.body property.
Note As req.body's shape is based on user-controlled input, all
properties and values in this object are untrusted and should be validated
before trusting. For example, req.body.foo.toString() may fail in multiple
ways, for example the foo property may not be there or may not be a string,
and toString may not be a function and instead a string or other user input.
Learn about the anatomy of an HTTP transaction in Node.js.
This does not handle multipart bodies, due to their complex and typically large nature.
$ npm install body-parser-yieldable
const bodyParserYieldable = require('body-parser-yieldable');
const jsonParser = bodyParserYieldable([options]);
Returns middleware that only parses json and only looks at requests where
the Content-Type header matches the type option. This parser accepts any
Unicode encoding of the body and supports automatic inflation of gzip and
deflate encodings.
A new body object containing the parsed data is populated on the request
object after the middleware (i.e. req.body).
The function takes an optional options object that may contain any of
the following keys:
When set to true, then deflated (compressed) bodies will be inflated; when
false, deflated bodies are rejected. Defaults to true.
Controls the maximum request body size. If this is a number, then the value
specifies the number of bytes; if it is a string, the value is passed to the
bytes library for parsing. Defaults
to '100kb'.
The reviver option is passed directly to yieldableJSON.parseAsync as the second
argument. You can find more information on this argument
in the README documentation about APIs/parseAsync/reviver.
The intensity option is passed directly to yieldableJSON.parseAsync as the third
argument. You can find more information on this argument
in the README documentation about APIs/parseAsync/intensity.
When set to true, will only accept arrays and objects; when false will
accept anything yieldableJSON.parseAsync accepts. Defaults to true.
The type option is used to determine what media type the middleware will
parse. This option can be a string, array of strings, or a function. If not a
function, type option is passed directly to the
type-is library and this can
be an extension name (like json), a mime type (like application/json), or
a mime type with a wildcard (like */* or */json). If a function, the type
option is called as fn(req) and the request is parsed if it returns a truthy
value. Defaults to application/json.
The verify option, if supplied, is called as verify(req, res, buf, encoding),
where buf is a Buffer of the raw request body and encoding is the
encoding of the request. The parsing can be aborted by throwing an error.
This example demonstrates adding a generic JSON and URL-encoded parser as a top-level middleware, which will parse the bodies of all incoming requests. This is the simplest setup.
const express = require('express');
const bodyParser = require('body-parser');
const bodyParserYieldable = require('body-parser-yieldable');
const app = express();
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json in async mode
app.use(bodyParserYieldable());
app.use(function (req, res) {
res.setHeader('Content-Type', 'text/plain');
res.write('you posted:\n');
res.end(JSON.stringify(req.body, null, 2));
})
This example demonstrates adding body parsers specifically to the routes that need them. In general, this is the most recommended way to use body-parser with Express.
const express = require('express');
const bodyParser = require('body-parser');
const bodyParserYieldable = require('body-parser-yieldable');
var app = express();
// create application/json async parser
var jsonParser = bodyParserYieldable();
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false });
// POST /login gets urlencoded bodies
app.post('/login', urlencodedParser, function (req, res) {
res.send('welcome, ' + req.body.username);
});
// POST /api/users gets JSON bodies
app.post('/api/users', jsonParser, function (req, res) {
// create user in req.body
});
All the parsers accept a type option which allows you to change the
Content-Type that the middleware will parse.
const express = require('express');
const bodyParser = require('body-parser');
const bodyParserYieldable = require('body-parser-yieldable');
var app = express();
// parse various different custom JSON types as JSON
app.use(bodyParserYieldable({ type: 'application/*+json' }));
// parse some custom thing into a Buffer
app.use(bodyParser.raw({ type: 'application/vnd.custom-type' }));
// parse an HTML body into a string
app.use(bodyParser.text({ type: 'text/html' }));
FAQs
body-parse with yieldable-json option
The npm package body-parser-yieldable receives a total of 5 weekly downloads. As such, body-parser-yieldable popularity was classified as not popular.
We found that body-parser-yieldable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.