Configs2026年7月7日·1 分钟阅读

formidable — Fast Streaming Multipart Form Parser for Node.js

The most widely used multipart form data parser for Node.js, handling file uploads with streaming efficiency.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
formidable Overview
先审查命令
npx -y tokrepo@latest install 95efd7f1-799e-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

formidable is a streaming multipart form data parser for Node.js. It handles file uploads efficiently by writing incoming data directly to disk or a custom destination as it arrives, rather than buffering entire files in memory. Originally created in 2010 by Felix Geisendorfer, it remains one of the most downloaded file upload parsers in the Node.js ecosystem.

What formidable Does

  • Parses multipart/form-data requests for file uploads
  • Parses application/x-www-form-urlencoded and JSON request bodies
  • Streams uploaded files directly to disk to minimize memory usage
  • Provides progress events for upload monitoring
  • Supports pluggable file storage backends

Architecture Overview

formidable uses a streaming state machine to parse incoming HTTP request bodies. As data chunks arrive, the parser identifies multipart boundaries, extracts headers, and routes file content to writable streams. This architecture means a 1 GB upload never occupies more than a few kilobytes of memory. The parser emits events for each field, file start, file end, and progress update. A plugin system allows replacing the default file writer with custom backends like cloud storage.

Self-Hosting & Configuration

  • Install via npm: npm install formidable
  • Set upload directory: formidable({ uploadDir: '/tmp/uploads' })
  • Limit file size: formidable({ maxFileSize: 10 * 1024 * 1024 }) for 10 MB
  • Allow multiple files per field: formidable({ multiples: true })
  • Use with Express: wrap in middleware or call form.parse(req) inside a route handler

Key Features

  • Streaming parser with minimal memory footprint even for large uploads
  • Built-in support for multipart, urlencoded, and JSON content types
  • File size and field count limits to prevent abuse
  • Upload progress events for building progress bars
  • Pluggable file handling for custom storage destinations

Comparison with Similar Tools

  • multer — Express-specific middleware; formidable works with any Node.js HTTP server
  • busboy — lower-level streaming parser; formidable adds file management and a higher-level API
  • multiparty — similar streaming approach; formidable has broader adoption and active maintenance
  • express-fileupload — simpler API but buffers files in memory; formidable streams to disk by default

FAQ

Q: Does formidable work with Express? A: Yes. Call form.parse(req) inside an Express route handler. It does not require Express-specific middleware.

Q: How do I limit upload file size? A: Set maxFileSize in the options: formidable({ maxFileSize: 5 * 1024 * 1024 }) for a 5 MB limit.

Q: Can I upload files to cloud storage instead of disk? A: Yes. Use the plugin system or handle the fileBegin event to pipe file data to a cloud storage SDK stream.

Q: Does it support multiple file uploads in a single field? A: Yes. Enable with formidable({ multiples: true }). Files arrive as an array in the parsed result.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产