{"id":14969181,"url":"https://github.com/fastify/busboy","last_synced_at":"2025-05-14T21:10:59.770Z","repository":{"id":37954495,"uuid":"432454387","full_name":"fastify/busboy","owner":"fastify","description":"A streaming parser for HTML form data for node.js","archived":false,"fork":false,"pushed_at":"2025-05-01T18:43:56.000Z","size":608,"stargazers_count":104,"open_issues_count":8,"forks_count":19,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-01T19:41:04.036Z","etag":null,"topics":["fastify-fork","fastify-library"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@fastify/busboy","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mscdex/busboy","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2021-11-27T12:25:19.000Z","updated_at":"2025-05-01T18:43:58.000Z","dependencies_parsed_at":"2023-10-01T20:34:38.967Z","dependency_job_id":"ab719637-1595-4380-acd6-0a8d8165480a","html_url":"https://github.com/fastify/busboy","commit_stats":{"total_commits":311,"total_committers":32,"mean_commits":9.71875,"dds":0.5144694533762058,"last_synced_commit":"b950e70fbf5cca7a3e32c0efdd291e66e1680ed6"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fbusboy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fbusboy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fbusboy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fbusboy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/busboy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253980062,"owners_count":21994042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify-fork","fastify-library"],"created_at":"2024-09-24T13:41:18.407Z","updated_at":"2025-05-14T21:10:54.743Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","readme":"# busboy\n\n\u003cdiv align=\"center\"\u003e\n\n[![Build Status](https://github.com/fastify/busboy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/busboy/actions)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n[![Security Responsible Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/fastify/.github/blob/main/SECURITY.md)\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![NPM version](https://img.shields.io/npm/v/@fastify/busboy.svg?style=flat)](https://www.npmjs.com/package/@fastify/busboy)\n[![NPM downloads](https://img.shields.io/npm/dm/@fastify/busboy.svg?style=flat)](https://www.npmjs.com/package/@fastify/busboy)\n\n\u003c/div\u003e\n\nDescription\n===========\n\nA Node.js module for parsing incoming HTML form data.\n\nThis is an officially supported fork by [fastify](https://github.com/fastify/) organization of the amazing library [originally created](https://github.com/mscdex/busboy) by Brian White,\naimed at addressing long-standing issues with it.\n\nBenchmark (Mean time for 500 Kb payload, 2000 cycles, 1000 cycle warmup):\n\n| Library               | Version | Mean time in nanoseconds (less is better) |\n|-----------------------|---------|-------------------------------------------|\n| busboy                | 0.3.1   | `340114`                                  |\n| @fastify/busboy       | 1.0.0   | `270984`                                  |\n\n[Changelog](https://github.com/fastify/busboy/blob/main/CHANGELOG.md) since busboy 0.31.\n\nRequirements\n============\n\n* [Node.js](http://nodejs.org/) 10+\n\n\nInstall\n=======\n\n    npm i @fastify/busboy\n\n\nExamples\n========\n\n* Parsing (multipart) with default options:\n\n```javascript\nconst http = require('node:http');\nconst { inspect } = require('node:util');\nconst Busboy = require('@fastify/busboy');\n\nhttp.createServer((req, res) =\u003e {\n  if (req.method === 'POST') {\n    const busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', (fieldname, file, filename, encoding, mimetype) =\u003e {\n      console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`);\n      file.on('data', data =\u003e {\n        console.log(`File [${fieldname}] got ${data.length} bytes`);\n      });\n      file.on('end', () =\u003e {\n        console.log(`File [${fieldname}] Finished`);\n      });\n    });\n    busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) =\u003e {\n      console.log(`Field [${fieldname}]: value: ${inspect(val)}`);\n    });\n    busboy.on('finish', () =\u003e {\n      console.log('Done parsing form!');\n      res.writeHead(303, { Connection: 'close', Location: '/' });\n      res.end();\n    });\n    req.pipe(busboy);\n  } else if (req.method === 'GET') {\n    res.writeHead(200, { Connection: 'close' });\n    res.end(`\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\n               \u003cform method=\"POST\" enctype=\"multipart/form-data\"\u003e\n                \u003cinput type=\"text\" name=\"textfield\"\u003e\u003cbr\u003e\n                \u003cinput type=\"file\" name=\"filefield\"\u003e\u003cbr\u003e\n                \u003cinput type=\"submit\"\u003e\n              \u003c/form\u003e\n            \u003c/body\u003e\u003c/html\u003e`);\n  }\n}).listen(8000, () =\u003e {\n  console.log('Listening for requests');\n});\n\n// Example output, using http://nodejs.org/images/ryan-speaker.jpg as the file:\n//\n// Listening for requests\n// File [filefield]: filename: ryan-speaker.jpg, encoding: binary\n// File [filefield] got 11971 bytes\n// Field [textfield]: value: 'testing! :-)'\n// File [filefield] Finished\n// Done parsing form!\n```\n\n* Save all incoming files to disk:\n\n```javascript\nconst http = require('node:http');\nconst path = require('node:path');\nconst os = require('node:os');\nconst fs = require('node:fs');\n\nconst Busboy = require('@fastify/busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    const busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {\n      var saveTo = path.join(os.tmpdir(), path.basename(fieldname));\n      file.pipe(fs.createWriteStream(saveTo));\n    });\n    busboy.on('finish', function() {\n      res.writeHead(200, { 'Connection': 'close' });\n      res.end(\"That's all folks!\");\n    });\n    return req.pipe(busboy);\n  }\n  res.writeHead(404);\n  res.end();\n}).listen(8000, function() {\n  console.log('Listening for requests');\n});\n```\n\n* Parsing (urlencoded) with default options:\n\n```javascript\nconst http = require('node:http');\nconst { inspect } = require('node:util');\n\nconst Busboy = require('@fastify/busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    const busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {\n      console.log('File [' + fieldname + ']: filename: ' + filename);\n      file.on('data', function(data) {\n        console.log('File [' + fieldname + '] got ' + data.length + ' bytes');\n      });\n      file.on('end', function() {\n        console.log('File [' + fieldname + '] Finished');\n      });\n    });\n    busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {\n      console.log('Field [' + fieldname + ']: value: ' + inspect(val));\n    });\n    busboy.on('finish', function() {\n      console.log('Done parsing form!');\n      res.writeHead(303, { Connection: 'close', Location: '/' });\n      res.end();\n    });\n    req.pipe(busboy);\n  } else if (req.method === 'GET') {\n    res.writeHead(200, { Connection: 'close' });\n    res.end('\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\\\n               \u003cform method=\"POST\"\u003e\\\n                \u003cinput type=\"text\" name=\"textfield\"\u003e\u003cbr /\u003e\\\n                \u003cselect name=\"selectfield\"\u003e\\\n                  \u003coption value=\"1\"\u003e1\u003c/option\u003e\\\n                  \u003coption value=\"10\"\u003e10\u003c/option\u003e\\\n                  \u003coption value=\"100\"\u003e100\u003c/option\u003e\\\n                  \u003coption value=\"9001\"\u003e9001\u003c/option\u003e\\\n                \u003c/select\u003e\u003cbr /\u003e\\\n                \u003cinput type=\"checkbox\" name=\"checkfield\"\u003eNode.js rules!\u003cbr /\u003e\\\n                \u003cinput type=\"submit\"\u003e\\\n              \u003c/form\u003e\\\n            \u003c/body\u003e\u003c/html\u003e');\n  }\n}).listen(8000, function() {\n  console.log('Listening for requests');\n});\n\n// Example output:\n//\n// Listening for requests\n// Field [textfield]: value: 'testing! :-)'\n// Field [selectfield]: value: '9001'\n// Field [checkfield]: value: 'on'\n// Done parsing form!\n```\n\n\nAPI\n===\n\n_Busboy_ is a _Writable_ stream\n\nBusboy (special) events\n-----------------------\n\n* **file**(\u003c _string_ \u003efieldname, \u003c _ReadableStream_ \u003estream, \u003c _string_ \u003efilename, \u003c _string_ \u003etransferEncoding, \u003c _string_ \u003emimeType) - Emitted for each new file form field found. `transferEncoding` contains the 'Content-Transfer-Encoding' value for the file stream. `mimeType` contains the 'Content-Type' value for the file stream.\n    * Note: if you listen for this event, you should always handle the `stream` no matter if you care about the file contents or not (e.g. you can simply just do `stream.resume();` if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about **any** incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards `files` and `parts` limits).\n    * If a configured file size limit was reached, `stream` will both have a boolean property `truncated` (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.\n    * The property `bytesRead` informs about the number of bytes that have been read so far.\n\n* **field**(\u003c _string_ \u003efieldname, \u003c _string_ \u003evalue, \u003c _boolean_ \u003efieldnameTruncated, \u003c _boolean_ \u003evalueTruncated, \u003c _string_ \u003etransferEncoding, \u003c _string_ \u003emimeType) - Emitted for each new non-file field found.\n\n* **partsLimit**() - Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.\n\n* **filesLimit**() - Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.\n\n* **fieldsLimit**() - Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.\n\n\nBusboy methods\n--------------\n\n* **(constructor)**(\u003c _object_ \u003econfig) - Creates and returns a new Busboy instance.\n\n    * The constructor takes the following valid `config` settings:\n\n        * **headers** - _object_ - These are the HTTP headers of the incoming request, which are used by individual parsers.\n\n        * **autoDestroy** - _boolean_ - Whether this stream should automatically call .destroy() on itself after ending. (Default: false).\n\n        * **highWaterMark** - _integer_ - highWaterMark to use for this Busboy instance (Default: WritableStream default).\n\n        * **fileHwm** - _integer_ - highWaterMark to use for file streams (Default: ReadableStream default).\n\n        * **defCharset** - _string_ - Default character set to use when one isn't defined (Default: 'utf8').\n\n        * **preservePath** - _boolean_ - If paths in the multipart 'filename' field shall be preserved. (Default: false).\n\n        * **isPartAFile** - __function__ - Use this function to override the default file detection functionality. It has following parameters:\n\n            * fieldName - __string__ The name of the field.\n\n            * contentType - __string__ The content-type of the part, e.g. `text/plain`, `image/jpeg`, `application/octet-stream`\n\n            * fileName - __string__ The name of a file supplied by the part.\n\n          (Default: `(fieldName, contentType, fileName) =\u003e (contentType === 'application/octet-stream' || fileName !== undefined)`)\n\n        * **limits** - _object_ - Various limits on incoming data. Valid properties are:\n\n            * **fieldNameSize** - _integer_ - Max field name size (in bytes) (Default: 100 bytes).\n\n            * **fieldSize** - _integer_ - Max field value size (in bytes) (Default: 1 MiB, which is 1024 x 1024 bytes).\n\n            * **fields** - _integer_ - Max number of non-file fields (Default: Infinity).\n\n            * **fileSize** - _integer_ - For multipart forms, the max file size (in bytes) (Default: Infinity).\n\n            * **files** - _integer_ - For multipart forms, the max number of file fields (Default: Infinity).\n\n            * **parts** - _integer_ - For multipart forms, the max number of parts (fields + files) (Default: Infinity).\n\n            * **headerPairs** - _integer_ - For multipart forms, the max number of header key=\u003evalue pairs to parse **Default:** 2000\n\n            * **headerSize** - _integer_ - For multipart forms, the max size of a multipart header **Default:** 81920.\n\n    * The constructor can throw errors:\n\n        * **Busboy expected an options-Object.** - Busboy expected an Object as first parameters.\n\n        * **Busboy expected an options-Object with headers-attribute.** - The first parameter is lacking of a headers-attribute.\n\n        * **Limit $limit is not a valid number** - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number.\n\n        * **Unsupported Content-Type.** - The `Content-Type` isn't one Busboy can parse.\n\n        * **Missing Content-Type-header.** - The provided headers don't include `Content-Type` at all.\n","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Fbusboy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Fbusboy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Fbusboy/lists"}