Registry / http-networking / parted

parted

JSON →
library0.1.1jsnpmunverified

Parted is an abandoned Node.js library, last updated in 2013 at version 0.1.1, designed to parse streaming `multipart`, `application/json`, and `application/x-www-form-urlencoded` request bodies. It differentiates itself by offering a streaming approach to parsing and including a built-in Express middleware that automatically selects the appropriate parser based on the request's `Content-Type`. The library aimed for lazy loading of individual parsers to minimize memory footprint. For multipart requests, it provides access to uploaded files via temporary paths and supports nested fields. Despite its initial goals, the project is no longer maintained, making it unsuitable for modern applications due to potential security vulnerabilities and lack of compatibility with contemporary Node.js versions and best practices.

npm install parted
INSTALL
IMPORT
SIG · PARTED
P
parted
http-networkingjavascriptv0.1.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.

parted
const parted = require('parted');
import parted from 'parted';
This package exclusively uses CommonJS `require` syntax. It does not support ES Modules.
multipart
const multipartParser = require('parted').multipart;
import { multipart } from 'parted';
Access individual parsers directly from the main `require`d object. This is a CommonJS-only pattern.

This quickstart sets up an Express server using `parted` middleware to handle multipart file uploads and JSON body parsing. It demonstrates how to configure file storage limits and access parsed fields (`req.body`) and files (`req.files`).

const express = require('express'); const parted = require('parted'); const path = require('path'); const fs = require('fs'); const app = express(); const PORT = 3000; // Ensure an uploads directory exists const uploadsDir = path.join(__dirname, 'uploads'); if (!fs.existsSync(uploadsDir)) { fs.mkdirSync(uploadsDir); } // Parted middleware configuration app.use(parted({ path: uploadsDir, // Custom file path for uploads limit: 10 * 1024, // Memory usage limit per request (10KB for fields) diskLimit: 5 * 1024 * 1024, // Disk usage limit per request (5MB for files) stream: true // Enable streaming for JSON/QS (otherwise buffered) })); app.get('/', (req, res) => { res.send(` <h1>Upload a File</h1> <form action="/upload" method="post" enctype="multipart/form-data"> <input type="text" name="description" placeholder="Description"> <input type="file" name="myFile"> <button type="submit">Upload</button> </form> <h1>Send JSON</h1> <form action="/api/data" method="post" onsubmit="event.preventDefault(); fetch(this.action, {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({key: 'value', another: 123})}).then(res => res.text()).then(alert);"> <button type="submit">Send JSON</button> </form> `); }); app.post('/upload', (req, res) => { console.log('Received upload request.'); console.log('Body fields:', req.body); // Text fields console.log('Uploaded files:', req.files); // File fields if (req.files && req.files.myFile) { const fileInfo = req.files.myFile; const tempPath = fileInfo.path; // Temporary path where parted saved the file const newPath = path.join(uploadsDir, fileInfo.name); // In a real app, you'd move/process the file, not just log temp path console.log(`File '${fileInfo.name}' saved temporarily at: ${tempPath}`); res.status(200).send(`File uploaded: ${fileInfo.name}, Description: ${req.body.description}`); } else { res.status(400).send('No file uploaded or file part named "myFile" not found.'); } }); app.post('/api/data', (req, res) => { console.log('Received JSON data:', req.body); res.json({ message: 'JSON received!', data: req.body }); }); app.listen(PORT, () => { console.log(`Server listening on http://localhost:${PORT}`); console.log(`Uploads will be saved to: ${uploadsDir}`); });
Debug
Known issues
breakingThis package is explicitly abandoned and has not been updated since 2013. It is not compatible with modern Node.js versions (e.g., v16+), ES Modules, or contemporary web security practices. Do not use in production.
fix
Migrate to an actively maintained body parser like `formidable` (for multipart), `multer` (for Express), or `@mjackson/multipart-parser` for streaming multipart parsing. For JSON/urlencoded, Express's built-in `express.json()` and `express.urlencoded()` middlewares are standard.
affects: All versions (<1.0.0)
gotchaParted uses synchronous file system operations (e.g., `fs.mkdirSync` implicitly in some configurations) and does not inherently support `async/await` patterns for stream handling, which can block the event loop in high-load scenarios. Its internal stream handling is dated.
fix
Modern Node.js applications should leverage `fs.promises` and `async/await` for non-blocking I/O. Actively maintained alternatives are built with asynchronous operations in mind.
affects: All versions (<1.0.0)
deprecatedThe default behavior for JSON and URL-encoded parsers is to buffer the entire request body unless the `stream: true` option is explicitly set. This can lead to increased memory usage for large non-file payloads, despite the library's 'streaming' claim.
fix
Always set `stream: true` in the `parted` middleware options if you intend for streaming behavior for JSON/URL-encoded bodies. However, for JSON/URL-encoded, modern Express built-in parsers are generally more efficient and safer.
affects: All versions (<1.0.0)
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `parted` (a CommonJS module) within an ES Module (ESM) file (e.g., when `type: module` is set in `package.json` or `.mjs` file extension).
fix
Ensure your project is configured for CommonJS (remove `"type": "module"` from `package.json` or rename file to `.cjs`), or, preferably, switch to a modern body parser that supports ESM.
TypeError: Cannot read properties of undefined (reading 'body') or (reading 'files')
The `parted` middleware was either not applied to the Express app or was applied incorrectly (e.g., after the route handler), meaning `req.body` and `req.files` were not populated.
fix
Ensure `app.use(parted(...))` is called before any route handlers that need to access `req.body` or `req.files` for parsed data.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
parted — npm install parted · libregistry