Registry / devops / koa-formidable

koa-formidable

JSON →
library1.1.0jsnpmunverified

Formidable middleware for Koa, version 1.1.0. Parses multipart/form-data (file uploads) and urlencoded bodies, adding `body` and `files` to `ctx.request`. Supports both automatic middleware and manual parsing via `formidable.parse(opts, ctx)`. Low maintenance, primarily for older Koa (generator-based) but works with Koa v2 when wrapped in `koa-convert`. Last updated in 2015; consider modern alternatives like `koa-body` or `@koa/multer`.

npm install koa-formidable
INSTALL
IMPORT
SIG · KOA-FORMIDABLE
K
koa-formidable
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formidable
const formidable = require('koa-formidable')
import formidable from 'koa-formidable'
Package does not ship ES modules; only CommonJS require() works.
formidable.parse
const result = yield formidable.parse(opts, ctx)
const result = await formidable.parse(opts, ctx)
Assumes generator-based Koa (co); for async/await, use koa-convert or wrap manually.
formidable (middleware)
app.use(formidable(opts))
app.use(formidable.parse(opts))
formidable(opts) returns a generator middleware; do not call parse() unless doing manual parsing.

Minimal Koa app that parses form data and logs body and files.

const Koa = require('koa'); const formidable = require('koa-formidable'); const app = new Koa(); app.use(formidable()); app.use(function* (next) { console.log('Body:', this.request.body); console.log('Files:', this.request.files); this.body = 'Done'; }); app.listen(3000);
Debug
Known issues
breakingIn version 1.0.0, parsed body and files are now added to `ctx.request` instead of modifying `ctx.req` directly.
fix
Access body and files via `this.request.body` and `this.request.files`, not `this.req.body`.
affects: >=1.0.0
deprecatedThis package is unmaintained; last release in 2015. It only supports generator-based Koa (Koa v1).
fix
Consider using koa-body, @koa/multer, or koa2-formidable for Koa v2.
affects: >=1.0.0
gotchaWhen using async/await with Koa v2, you must wrap the generator middleware with koa-convert.
fix
Use koa-convert: app.use(convert(formidable())).
affects: >=1.0.0
gotchaThe formidable.parse function expects a callback (yield) but returns a Promise only if you wrap it. It does not return a native Promise.
fix
Use co or koa-convert to handle the generator. Alternatively, use util.promisify.
affects: >=1.0.0
gotchaOptions passed to formidable(opts) are directly forwarded to Formidable's IncomingForm options. Some options may not work as expected if the formidable version differs.
fix
Check the version of formidable installed; if needed, pin formidable version in package.json.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'body' of undefined
Middleware not applied or applied after route handler.
fix
Ensure app.use(formidable()) is called before any route that accesses body/files.
Error: yield is reserved in async functions
Using async/await instead of generator functions with co.
fix
Use generators: `app.use(function*() { ... })` OR wrap with `co.wrap` or `koa-convert`.
TypeError: formidable is not a function
Wrong import/require call.
fix
Use `const formidable = require('koa-formidable')` (CommonJS). Do not use ES6 import.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
formidablerequiredcore parsing engine for multipart and urlencoded data
Agent activity
27 hits · last 30 days
node
24
Resources
koa-formidable — npm install koa-formidable · libregistry