Gathering detailed insights and metrics for @koa/bodyparser
Gathering detailed insights and metrics for @koa/bodyparser
Gathering detailed insights and metrics for @koa/bodyparser
Gathering detailed insights and metrics for @koa/bodyparser
npm install @koa/bodyparser
Typescript
Module System
Min. Node Version
TypeScript (100%)
Total Downloads
1,767,427
Last Day
2,091
Last Week
41,937
Last Month
165,134
Last Year
1,379,008
MIT License
1,320 Stars
116 Commits
121 Forks
20 Watchers
5 Branches
37 Contributors
Updated on Jun 05, 2025
Minified
Minified + Gzipped
Latest Version
6.0.0
Package Id
@koa/bodyparser@6.0.0
Unpacked Size
46.95 kB
Size
9.07 kB
File Count
22
Published on
Jun 05, 2025
Cumulative downloads
Total Downloads
Last Day
-2.9%
2,091
Compared to previous day
Last Week
-3.9%
41,937
Compared to previous week
Last Month
9.6%
165,134
Compared to previous month
Last Year
255%
1,379,008
Compared to previous year
4
1
Koa body parsing middleware, based on co-body. support json
, form
and text
type body.
Parse incoming request bodies in a middleware before your handlers, available under the ctx.request.body
property.
⚠ Notice: This module doesn't support parsing multipart format data, please use
@koa/multer
to parse multipart format data.
1$ npm i @koa/bodyparser --save
1const Koa = require("koa"); 2const { bodyParser } = require("@koa/bodyparser"); 3 4const app = new Koa(); 5app.use(bodyParser()); 6 7app.use((ctx) => { 8 // the parsed body will store in ctx.request.body 9 // if nothing was parsed, body will be an empty object {} 10 ctx.body = ctx.request.body; 11});
patchNode: patch request body to Node's ctx.req
, default is false
.
enableTypes: parser will only parse when request type hits enableTypes, support json/form/text/xml
, default is ['json', 'form']
.
encoding: requested encoding. Default is utf-8
by co-body
.
formLimit: limit of the urlencoded
body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 56kb
.
jsonLimit: limit of the json
body. Default is 1mb
.
textLimit: limit of the text
body. Default is 1mb
.
xmlLimit: limit of the xml
body. Default is 1mb
.
jsonStrict: when set to true, JSON parser will only accept arrays and objects. Default is true
. See strict mode in co-body
. In strict mode, ctx.request.body
will always be an object(or array), this avoid lots of type judging. But text body will always return string type.
detectJSON: custom json request detect function. Default is null
.
1app.use( 2 bodyParser({ 3 detectJSON(ctx) { 4 return /\.json$/i.test(ctx.path); 5 }, 6 }) 7);
extendTypes: support extend types:
1app.use(
2 bodyParser({
3 extendTypes: {
4 // will parse application/x-javascript type body as a JSON string
5 json: ["application/x-javascript"],
6 },
7 })
8);
onError: support custom error handle, if koa-bodyparser
throw an error, you can customize the response like:
1app.use( 2 bodyParser({ 3 onError(err, ctx) { 4 ctx.throw(422, "body parse error"); 5 }, 6 }) 7);
enableRawChecking: support the already parsed body on the raw request by override and prioritize the parsed value over the sended payload. (default is false
)
parsedMethods: declares the HTTP methods where bodies will be parsed, default ['POST', 'PUT', 'PATCH']
.
disableBodyParser: you can dynamic disable body parser by set ctx.disableBodyParser = true
.
1app.use((ctx, next) => { 2 if (ctx.path === "/disable") ctx.disableBodyParser = true; 3 return next(); 4}); 5app.use(bodyParser());
You can access raw request body by ctx.request.rawBody
after koa-bodyparser
when:
koa-bodyparser
parsed the request body.ctx.request.rawBody
is not present before koa-bodyparser
.To use koa-bodyparser
with koa@1.x.x, please use bodyparser 2.x.
1$ npm install koa-bodyparser@2 --save
usage
1const Koa = require("koa"); 2const bodyParser = require("@koa/bodyparser"); 3 4const app = new Koa(); 5app.use(bodyParser()); 6 7app.use((ctx) => { 8 // the parsed body will store in ctx.request.body 9 // if nothing was parsed, body will be an empty object {} 10 ctx.body = ctx.request.body; 11});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
6 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More