
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
koa-parser
Advanced tools
a body parser for koa. support json, form(urlencoded), multipart and text type body.
const Koa = require('koa')
const parser = require('koa-parser')
const port = 3000
const app = new Koa()
app.use(parser())
app.use(async (ctx, next) => {
// if nothing was parsed, body will be undefined
if (ctx.request.body !== undefined) {
ctx.body = ctx.request.body
}
await next()
})
app.listen(port)
console.error(`listening on port ${port}`)

app.use(parser({
encoding?: string, // requested encoding
error?: (err: any, ctx: Koa.Context) => any, // support custom parser error handle
json?: string | string[], // support json parser types
multipart?: string | string[], // support multipart(form-data) parser types
text?: string | string[], // support text parser types
urlencoded?: string | string[] // support urlencoded(form) parser types
}))
encoding: requested encoding. Default is utf-8
error: support custom error handle, Default is false. if koa-bodyparser throw an error, you can customize the response like:
app.use(parser({
error (err, ctx) {
console.log(err)
ctx.throw(err, 422)
}
}))
json: Extended support for json parsing options, The default supported types are ['application/json', 'application/json-patch+json', 'application/vnd.api+json', 'application/csp-report']. you can customize the type like:
// json will be support default types and application/x-javascript
app.use(parser({
json: 'application/x-javascript' // You can also pass parameters in an array
}))
multipart: Extended support for multipart(form-data) parsing options, The default supported types are ['multipart/form-data']
text: Extended support for text parsing options, The default supported types are ['text/plain']
urlencoded: Extended support for urlencoded(form) parsing options, The default supported types are ['application/x-www-form-urlencoded']
FAQs
a body parser for koa
We found that koa-parser 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

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.