{"library":"parted","title":"Streaming Body Parser for Node.js (Abandoned)","description":"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install parted"],"cli":null},"imports":["const parted = require('parted');","const multipartParser = require('parted').multipart;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const express = require('express');\nconst parted = require('parted');\nconst path = require('path');\nconst fs = require('fs');\n\nconst app = express();\nconst PORT = 3000;\n\n// Ensure an uploads directory exists\nconst uploadsDir = path.join(__dirname, 'uploads');\nif (!fs.existsSync(uploadsDir)) {\n  fs.mkdirSync(uploadsDir);\n}\n\n// Parted middleware configuration\napp.use(parted({\n  path: uploadsDir, // Custom file path for uploads\n  limit: 10 * 1024,  // Memory usage limit per request (10KB for fields)\n  diskLimit: 5 * 1024 * 1024, // Disk usage limit per request (5MB for files)\n  stream: true       // Enable streaming for JSON/QS (otherwise buffered)\n}));\n\napp.get('/', (req, res) => {\n  res.send(`\n    <h1>Upload a File</h1>\n    <form action=\"/upload\" method=\"post\" enctype=\"multipart/form-data\">\n      <input type=\"text\" name=\"description\" placeholder=\"Description\">\n      <input type=\"file\" name=\"myFile\">\n      <button type=\"submit\">Upload</button>\n    </form>\n    <h1>Send JSON</h1>\n    <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);\">\n      <button type=\"submit\">Send JSON</button>\n    </form>\n  `);\n});\n\napp.post('/upload', (req, res) => {\n  console.log('Received upload request.');\n  console.log('Body fields:', req.body); // Text fields\n  console.log('Uploaded files:', req.files); // File fields\n\n  if (req.files && req.files.myFile) {\n    const fileInfo = req.files.myFile;\n    const tempPath = fileInfo.path; // Temporary path where parted saved the file\n    const newPath = path.join(uploadsDir, fileInfo.name);\n\n    // In a real app, you'd move/process the file, not just log temp path\n    console.log(`File '${fileInfo.name}' saved temporarily at: ${tempPath}`);\n    res.status(200).send(`File uploaded: ${fileInfo.name}, Description: ${req.body.description}`);\n  } else {\n    res.status(400).send('No file uploaded or file part named \"myFile\" not found.');\n  }\n});\n\napp.post('/api/data', (req, res) => {\n  console.log('Received JSON data:', req.body);\n  res.json({ message: 'JSON received!', data: req.body });\n});\n\napp.listen(PORT, () => {\n  console.log(`Server listening on http://localhost:${PORT}`);\n  console.log(`Uploads will be saved to: ${uploadsDir}`);\n});\n","lang":"javascript","description":"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`).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}