Busboy
Streaming multipart/form-data parser for Node.js request bodies that emits files and fields as they arrive.
Official Documentation ↗v1.6. Check the official docs for the latest API surface.Installation
npm install busboypnpm add busboyMethods
No methods match this filter.
Streaming multipart/form-data parser for Node.js request bodies that emits files and fields as they arrive.
Overview
Busboy parses multipart/form-data incrementally. Constructed with the request headers, it consumes the request stream and emits file and field events as parts arrive, never holding a whole upload in memory.
The limits object is the safety surface: fileSize caps each file while the stream still fires a limit event, and fields, fieldNameSize, and files bound the rest of the request shape. Piping the file stream onward to disk or another destination keeps memory flat for arbitrarily large uploads.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
new Busboy— Creates a parser bound to the request headers, with limits for fields, files, and part sizes."file" event— Emitted per uploaded file part; file is a readable stream to consume or pipe while respecting the fileSize limit."field" event— Emitted for each non-file form field once its value is fully received, truncated flags reflecting the limits.req.pipe(busboy)— Feeds the raw request body into the parser; parts start emitting as bytes stream through.
Usage Notes
- Always set fileSize and files limits; unbounded parsing turns a single request into a disk-filling primitive.
- Consume or destroy every file stream, even on early validation errors, so the request body can finish draining.
- Prefer @fastify/busboy in new Fastify projects; it is the maintained fork with the same event API.
Common Pitfalls
- Listening for the finish of the request is not the same as finish of your write streams; await both before responding.
- Ignoring the limit event leaves truncated files on disk that look like successful uploads.
- Multiple files arrive as separate file events with the same field name; accumulate them instead of overwriting a single variable.
FAQ
- How do I reject files that exceed the size limit?
- Set limits.fileSize. The file stream then emits a limit event and stops producing data; destroy the write stream and delete the partial file. The request still finishes, so respond with 413 from your handler.
- How does Busboy differ from Multer?
- Multer is a higher-level Express middleware that buffers files to disk or memory and hands you tidy req.files. Busboy is the streaming layer underneath, which you use directly when you must pipe uploads onward, apply custom backpressure, or avoid framework coupling.
- Are uploaded filenames safe to use?
- No. Filenames are attacker-controlled strings that can contain path separators or unicode tricks. Generate your own storage name and keep the original only as metadata, validated and encoded for display.
Report a problem with this API docOpens a pre-filled issue on GitHub.