Registry / http-networking / multiparty

multiparty

JSON →
library0.0.1jsnpmunverified

multiparty is a Node.js library designed for parsing `multipart/form-data` HTTP requests, which are primarily used for handling file uploads. It offers streaming capabilities, allowing developers to process form fields and files incrementally as they are received, a key feature for handling large uploads efficiently without consuming excessive memory. The current stable version, 4.2.3, was last published approximately four years ago, indicating a maintenance-only or inactive development cadence rather than active feature development. The library's own documentation suggests `busboy` as a "faster alternative," highlighting a performance consideration. multiparty provides a straightforward, event-driven API centered around the `multiparty.Form` class, making it a functional choice for applications needing to handle file uploads in a Node.js environment, though users should be aware of its age and the existence of more modern, performance-optimized alternatives.

npm install multiparty
INSTALL
IMPORT
SIG · MULTIPARTY
M
multiparty
http-networkingjavascriptv0.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

multiparty
const multiparty = require('multiparty');
import multiparty from 'multiparty'; import * as multiparty from 'multiparty';
multiparty is a CommonJS module and does not support ES module import syntax (e.g., `import` statements). Use `require`.
multiparty.Form
const Form = multiparty.Form;
import { Form } from 'multiparty';
The Form class is a property of the main multiparty export. Destructuring imports like `import { Form } from 'multiparty'` will not work due to CommonJS architecture.

This quickstart sets up a basic Node.js HTTP server to handle `multipart/form-data` uploads using `multiparty`. It demonstrates parsing fields and files, writing files to a temporary directory, and includes important cleanup of those temporary files.

const multiparty = require('multiparty'); const http = require('http'); const util = require('util'); const path = require('path'); const fs = require('fs'); const os = require('os'); const UPLOAD_DIR = path.join(os.tmpdir(), 'multiparty-uploads'); fs.mkdirSync(UPLOAD_DIR, { recursive: true }); http.createServer(function(req, res) { if (req.url === '/upload' && req.method === 'POST') { const form = new multiparty.Form({ uploadDir: UPLOAD_DIR }); form.parse(req, function(err, fields, files) { if (err) { console.error('Error parsing form:', err.stack); res.writeHead(500, { 'content-type': 'text/plain' }); res.end('Error parsing form: ' + err.message); return; } res.writeHead(200, { 'content-type': 'text/plain' }); res.write('received upload:\n\n'); res.write(util.inspect({ fields: fields, files: files }) + '\n'); res.end('Files uploaded to: ' + UPLOAD_DIR + '\n'); // Clean up uploaded files (important!) Object.values(files).flat().forEach(file => { if (file && file.path) { fs.unlink(file.path, (unlinkErr) => { if (unlinkErr) console.error(`Failed to delete temporary file ${file.path}:`, unlinkErr); else console.log(`Deleted temporary file: ${file.path}`); }); } }); }); return; } res.writeHead(200, { 'content-type': 'text/html' }); res.end( '<form action="/upload" enctype="multipart/form-data" method="post">' + '<input type="text" name="title"><br/>' + '<input type="file" name="upload" multiple="multiple"><br/>' + '<input type="submit" value="Upload">' + '</form>' ); }).listen(8080, () => { console.log('Server listening on http://localhost:8080'); console.log('Temporary upload directory:', UPLOAD_DIR); });
Debug
Known issues
gotchamultiparty is generally slower than alternatives like `busboy`. For performance-critical applications or high-throughput servers, `busboy` or other modern libraries are often recommended.
fix
Evaluate alternatives like `busboy` or `multer` for better performance and more active development.
affects: >=0.10
breakingmultiparty is a CommonJS module. Attempting to use ES Module `import` syntax will result in a runtime error.
fix
Always use CommonJS `require` syntax: `const multiparty = require('multiparty');`.
affects: >=0.10
gotchaWhen listening to `part` events (e.g., `form.on('part', ...)`) without `autoFields` or `autoFiles`, you *must* actively read from or resume the `part` stream for both fields and files. Failing to do so will cause the request to hang and can lead to resource exhaustion.
fix
For each `part` event, ensure `part.resume()` is called (to discard data) or its data is fully consumed (e.g., `part.pipe(destinationStream)`).
affects: >=0.10
gotchaThe `maxFieldsSize`, `maxFields`, and `maxFilesSize` options define strict limits on incoming data. Exceeding these limits will emit an `error` event on the form, which must be handled to prevent application crashes.
fix
Implement robust error handling for `form.on('error', ...)` and configure limits appropriately in the `multiparty.Form` constructor based on expected usage.
affects: >=0.10
gotchaWhen `autoFiles` is enabled, files are written to a temporary directory (`uploadDir`, defaulting to `os.tmpdir()`). It is the developer's responsibility to move or delete these temporary files after processing, otherwise, they will persist, consuming disk space.
fix
After successful processing, use `fs.rename()` to move files to a permanent location or `fs.unlink()` to delete them. Ensure error handling for these file operations.
affects: >=0.10
Errors
Common errors & fixes
TypeError: multiparty.Form is not a constructor
Incorrect import of the multiparty library, often by attempting ES module default import or incorrect destructuring. multiparty is a CommonJS module.
fix
Ensure `multiparty` is required using `const multiparty = require('multiparty');` and `Form` is accessed as a property: `new multiparty.Form()`.
ERR_REQUIRE_ESM or SyntaxError: Cannot use import statement outside a module
Attempting to use `import` syntax with `multiparty`, which is a CommonJS module.
fix
Use CommonJS `require` syntax: `const multiparty = require('multiparty');`.
Request hangs indefinitely or server never responds to multipart POST request.
When using the `form.on('part', ...)` event listener, the `part` stream (for either fields or files) was not fully consumed or resumed.
fix
For every `part` emitted, ensure its data is read (e.g., `part.on('data', ...)` or `part.pipe(...)`) or explicitly skipped with `part.resume()`.
Error: maxFieldsSize exceeded
Error: maxFilesSize exceeded
The total size of form fields or files uploaded exceeded the configured `maxFieldsSize` or `maxFilesSize` limits, respectively.
fix
Increase the `maxFieldsSize` or `maxFilesSize` option in the `multiparty.Form` constructor if larger uploads are expected. Example: `new multiparty.Form({ maxFilesSize: 10 * 1024 * 1024 })` for 10MB total files.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
multiparty — npm install multiparty · libregistry