{"id":13553374,"url":"https://github.com/mscdex/busboy","last_synced_at":"2025-05-12T15:35:02.555Z","repository":{"id":8655356,"uuid":"10308334","full_name":"mscdex/busboy","owner":"mscdex","description":"A streaming parser for HTML form data for node.js","archived":false,"fork":false,"pushed_at":"2024-05-31T20:04:04.000Z","size":398,"stargazers_count":2914,"open_issues_count":35,"forks_count":215,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-05-09T01:14:03.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mscdex.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2013-05-27T05:18:36.000Z","updated_at":"2025-05-08T19:26:38.000Z","dependencies_parsed_at":"2024-06-18T10:57:02.295Z","dependency_job_id":"9f719b59-8b42-4369-88e4-0d882e1d776d","html_url":"https://github.com/mscdex/busboy","commit_stats":{"total_commits":192,"total_committers":17,"mean_commits":"11.294117647058824","dds":"0.11458333333333337","last_synced_commit":"6b3dcf69d38c1a8d53a0b3e4c88ba296f6c91525"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fbusboy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fbusboy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fbusboy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fbusboy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscdex","download_url":"https://codeload.github.com/mscdex/busboy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253336628,"owners_count":21892787,"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":[],"created_at":"2024-08-01T12:02:23.150Z","updated_at":"2025-05-12T15:35:02.473Z","avatar_url":"https://github.com/mscdex.png","language":"JavaScript","readme":"# Description\n\nA node.js module for parsing incoming HTML form data.\n\nChanges (breaking or otherwise) in v1.0.0 can be found [here](https://github.com/mscdex/busboy/issues/266).\n\n**Note:** If you are using node v18.0.0 or newer, please be aware of the node.js\nHTTP(S) server's [`requestTimeout`](https://nodejs.org/docs/latest/api/http.html#httpcreateserveroptions-requestlistener)\nconfiguration setting that is now enabled by default, which could cause upload\ninterruptions if the upload takes too long.\n\n# Requirements\n\n* [node.js](http://nodejs.org/) -- v10.16.0 or newer\n\n\n# Install\n\n    npm install busboy\n\n\n# Examples\n\n* Parsing (multipart) with default options:\n\n```js\nconst http = require('http');\n\nconst busboy = require('busboy');\n\nhttp.createServer((req, res) =\u003e {\n  if (req.method === 'POST') {\n    console.log('POST request');\n    const bb = busboy({ headers: req.headers });\n    bb.on('file', (name, file, info) =\u003e {\n      const { filename, encoding, mimeType } = info;\n      console.log(\n        `File [${name}]: filename: %j, encoding: %j, mimeType: %j`,\n        filename,\n        encoding,\n        mimeType\n      );\n      file.on('data', (data) =\u003e {\n        console.log(`File [${name}] got ${data.length} bytes`);\n      }).on('close', () =\u003e {\n        console.log(`File [${name}] done`);\n      });\n    });\n    bb.on('field', (name, val, info) =\u003e {\n      console.log(`Field [${name}]: value: %j`, val);\n    });\n    bb.on('close', () =\u003e {\n      console.log('Done parsing form!');\n      res.writeHead(303, { Connection: 'close', Location: '/' });\n      res.end();\n    });\n    req.pipe(bb);\n  } else if (req.method === 'GET') {\n    res.writeHead(200, { Connection: 'close' });\n    res.end(`\n      \u003chtml\u003e\n        \u003chead\u003e\u003c/head\u003e\n        \u003cbody\u003e\n          \u003cform method=\"POST\" enctype=\"multipart/form-data\"\u003e\n            \u003cinput type=\"file\" name=\"filefield\"\u003e\u003cbr /\u003e\n            \u003cinput type=\"text\" name=\"textfield\"\u003e\u003cbr /\u003e\n            \u003cinput type=\"submit\"\u003e\n          \u003c/form\u003e\n        \u003c/body\u003e\n      \u003c/html\u003e\n    `);\n  }\n}).listen(8000, () =\u003e {\n  console.log('Listening for requests');\n});\n\n// Example output:\n//\n// Listening for requests\n//   \u003c ... form submitted ... \u003e\n// POST request\n// File [filefield]: filename: \"logo.jpg\", encoding: \"binary\", mime: \"image/jpeg\"\n// File [filefield] got 11912 bytes\n// Field [textfield]: value: \"testing! :-)\"\n// File [filefield] done\n// Done parsing form!\n```\n\n* Save all incoming files to disk:\n\n```js\nconst { randomFillSync } = require('crypto');\nconst fs = require('fs');\nconst http = require('http');\nconst os = require('os');\nconst path = require('path');\n\nconst busboy = require('busboy');\n\nconst random = (() =\u003e {\n  const buf = Buffer.alloc(16);\n  return () =\u003e randomFillSync(buf).toString('hex');\n})();\n\nhttp.createServer((req, res) =\u003e {\n  if (req.method === 'POST') {\n    const bb = busboy({ headers: req.headers });\n    bb.on('file', (name, file, info) =\u003e {\n      const saveTo = path.join(os.tmpdir(), `busboy-upload-${random()}`);\n      file.pipe(fs.createWriteStream(saveTo));\n    });\n    bb.on('close', () =\u003e {\n      res.writeHead(200, { 'Connection': 'close' });\n      res.end(`That's all folks!`);\n    });\n    req.pipe(bb);\n    return;\n  }\n  res.writeHead(404);\n  res.end();\n}).listen(8000, () =\u003e {\n  console.log('Listening for requests');\n});\n```\n\n\n# API\n\n## Exports\n\n`busboy` exports a single function:\n\n**( _function_ )**(\u003c _object_ \u003econfig) - Creates and returns a new _Writable_ form parser stream.\n\n* Valid `config` properties:\n\n    * **headers** - _object_ - These are the HTTP headers of the incoming request, which are used by individual parsers.\n\n    * **highWaterMark** - _integer_ - highWaterMark to use for the parser stream. **Default:** node's _stream.Writable_ default.\n\n    * **fileHwm** - _integer_ - highWaterMark to use for individual file streams. **Default:** node's _stream.Readable_ default.\n\n    * **defCharset** - _string_ - Default character set to use when one isn't defined. **Default:** `'utf8'`.\n\n    * **defParamCharset** - _string_ - For multipart forms, the default character set to use for values of part header parameters (e.g. filename) that are not extended parameters (that contain an explicit charset). **Default:** `'latin1'`.\n\n    * **preservePath** - _boolean_ - If paths in filenames from file parts in a `'multipart/form-data'` request shall be preserved. **Default:** `false`.\n\n    * **limits** - _object_ - Various limits on incoming data. Valid properties are:\n\n        * **fieldNameSize** - _integer_ - Max field name size (in bytes). **Default:** `100`.\n\n        * **fieldSize** - _integer_ - Max field value size (in bytes). **Default:** `1048576` (1MB).\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-value pairs to parse. **Default:** `2000` (same as node's http module).\n\nThis function can throw exceptions if there is something wrong with the values in `config`. For example, if the Content-Type in `headers` is missing entirely, is not a supported type, or is missing the boundary for `'multipart/form-data'` requests.\n\n## (Special) Parser stream events\n\n* **file**(\u003c _string_ \u003ename, \u003c _Readable_ \u003estream, \u003c _object_ \u003einfo) - Emitted for each new file found. `name` contains the form field name. `stream` is a _Readable_ stream containing the file's data. No transformations/conversions (e.g. base64 to raw binary) are done on the file's data. `info` contains the following properties:\n\n    * `filename` - _string_ - If supplied, this contains the file's filename. **WARNING:** You should almost _never_ use this value as-is (especially if you are using `preservePath: true` in your `config`) as it could contain malicious input. You are better off generating your own (safe) filenames, or at the very least using a hash of the filename.\n\n    * `encoding` - _string_ - The file's `'Content-Transfer-Encoding'` value.\n\n    * `mimeType` - _string_ - The file's `'Content-Type'` value.\n\n    **Note:** If you listen for this event, you should always consume the `stream` whether you care about its contents or not (you can simply do `stream.resume();` if you want to discard/skip the contents), otherwise the `'finish'`/`'close'` event will never fire on the busboy parser stream.\n    However, if you aren't accepting files, you can either simply not listen for the `'file'` event at all or set `limits.files` to `0`, and any/all files will be automatically skipped (these skipped files will still count towards any configured `limits.files` and `limits.parts` limits though).\n\n    **Note:** If a configured `limits.fileSize` limit was reached for a file, `stream` will both have a boolean property `truncated` set to `true` (best checked at the end of the stream) and emit a `'limit'` event to notify you when this happens.\n\n* **field**(\u003c _string_ \u003ename, \u003c _string_ \u003evalue, \u003c _object_ \u003einfo) - Emitted for each new non-file field found. `name` contains the form field name. `value` contains the string value of the field. `info` contains the following properties:\n\n    * `nameTruncated` - _boolean_ - Whether `name` was truncated or not (due to a configured `limits.fieldNameSize` limit)\n\n    * `valueTruncated` - _boolean_ - Whether `value` was truncated or not (due to a configured `limits.fieldSize` limit)\n\n    * `encoding` - _string_ - The field's `'Content-Transfer-Encoding'` value.\n\n    * `mimeType` - _string_ - The field's `'Content-Type'` value.\n\n* **partsLimit**() - Emitted when the configured `limits.parts` limit has been reached. No more `'file'` or `'field'` events will be emitted.\n\n* **filesLimit**() - Emitted when the configured `limits.files` limit has been reached. No more `'file'` events will be emitted.\n\n* **fieldsLimit**() - Emitted when the configured `limits.fields` limit has been reached. No more `'field'` events will be emitted.\n","funding_links":[],"categories":["JavaScript","Packages","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fbusboy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscdex%2Fbusboy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fbusboy/lists"}