{"library":"multiparty","title":"multiparty","description":"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.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install multiparty"],"cli":null},"imports":["const multiparty = require('multiparty');","const Form = multiparty.Form;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const multiparty = require('multiparty');\nconst http = require('http');\nconst util = require('util');\nconst path = require('path');\nconst fs = require('fs');\nconst os = require('os');\n\nconst UPLOAD_DIR = path.join(os.tmpdir(), 'multiparty-uploads');\nfs.mkdirSync(UPLOAD_DIR, { recursive: true });\n\nhttp.createServer(function(req, res) {\n  if (req.url === '/upload' && req.method === 'POST') {\n    const form = new multiparty.Form({ uploadDir: UPLOAD_DIR });\n\n    form.parse(req, function(err, fields, files) {\n      if (err) {\n        console.error('Error parsing form:', err.stack);\n        res.writeHead(500, { 'content-type': 'text/plain' });\n        res.end('Error parsing form: ' + err.message);\n        return;\n      }\n\n      res.writeHead(200, { 'content-type': 'text/plain' });\n      res.write('received upload:\\n\\n');\n      res.write(util.inspect({ fields: fields, files: files }) + '\\n');\n      res.end('Files uploaded to: ' + UPLOAD_DIR + '\\n');\n\n      // Clean up uploaded files (important!)\n      Object.values(files).flat().forEach(file => {\n        if (file && file.path) {\n          fs.unlink(file.path, (unlinkErr) => {\n            if (unlinkErr) console.error(`Failed to delete temporary file ${file.path}:`, unlinkErr);\n            else console.log(`Deleted temporary file: ${file.path}`);\n          });\n        }\n      });\n    });\n    return;\n  }\n\n  res.writeHead(200, { 'content-type': 'text/html' });\n  res.end(\n    '<form action=\"/upload\" enctype=\"multipart/form-data\" method=\"post\">' +\n    '<input type=\"text\" name=\"title\"><br/>' +\n    '<input type=\"file\" name=\"upload\" multiple=\"multiple\"><br/>' +\n    '<input type=\"submit\" value=\"Upload\">' +\n    '</form>'\n  );\n}).listen(8080, () => {\n  console.log('Server listening on http://localhost:8080');\n  console.log('Temporary upload directory:', UPLOAD_DIR);\n});\n","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}