form-data

Build readable multipart/form-data streams in Node.js for forms and file uploads

Library
npm
v4.0.6
2,356 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
45 /100 Fair
Development Activity 8
Maintenance 0
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 78
Code Quality 80
Innovation 85
Learning Curve 82

form-data is a Node.js library for constructing readable multipart/form-data streams, the encoding browsers use to submit forms and file uploads. Its API is modeled on the XMLHttpRequest-2 FormData interface, so you append string, buffer, and stream values to a form and pipe or submit the result to any web application.

As one of the most-downloaded packages in the npm ecosystem, it is the standard building block behind file-upload support in HTTP clients like axios, node-fetch, and request. It handles boundary generation, content-type detection, content-length calculation, and header assembly so you can post files and mixed fields without hand-writing the multipart wire format.

What You Get

  • A FormData class that streams multipart bodies without buffering entire files in memory
  • Automatic boundary generation, content-type detection via mime-types, and content-length calculation
  • A built-in submit() helper plus getHeaders()/getBuffer() for integration with axios, node-fetch, and request
  • Hand-written TypeScript definitions (index.d.ts) for typed usage
  • Per-part options for filename, filepath, content type, custom headers, and known length

Common Use Cases

  • Uploading files from a Node.js backend to a third-party API or storage service
  • Posting mixed form fields (strings, buffers, file streams) to an HTTP endpoint
  • Providing the multipart body that HTTP clients such as axios and node-fetch send
  • Streaming large files as upload parts without loading them fully into memory

Under The Hood

Architecture

The core is a single FormData class in lib/form_data.js (~500 lines) that inherits from combined-stream’s CombinedStream, making the form itself a readable stream. append() wraps each value with a generated multipart header and trailing line break and pushes it onto the combined stream, deferring stream reads until the consumer pulls data. Length bookkeeping is split between _overheadLength, _valueLength, and a _valuesToMeasure queue that getLength() resolves in parallel via asynckit, while submit() builds an http/https request from a URL or options object and pipes the form into it.

Tech Stack

Pure JavaScript (100% of the repo) targeting Node >= 6, with hand-written TypeScript definitions in index.d.ts. Runtime dependencies are minimal and focused: combined-stream for stream concatenation, asynckit for parallel length measurement, mime-types for content-type detection, plus hasown and es-set-tostringtag for safe property and tag handling. Tooling uses ESLint (ljharb config), istanbul for coverage, tape for tests, and browserify to produce the browser build declared via the browser field.

Code Quality

The library is mature and well-tested: 29 integration test files under test/integration plus static tests cover boundaries, custom headers, length calculation, submission variants, and streaming. The code carries JSDoc annotations and is security-conscious — escapeHeaderParam() escapes CR, LF, and quotes to block multipart header injection, backed by dedicated test-header-injection.js and test-boundary-prediction.js tests. Error handling surfaces length-calculation failures through callbacks rather than swallowing them.

API Design

The public API is deliberately small and familiar, mirroring the browser XMLHttpRequest-2 FormData interface: append(), getHeaders(), getBoundary(), getBuffer(), getLength(), and submit(). Getting started takes only a few lines, per-part options (filename, contentType, knownLength, custom headers) cover advanced cases, and the README documents integration recipes for axios, node-fetch, and request. Consistent naming and thorough docs keep the learning curve low.

Used by 45 apps in this directory

TypeScript
96%
Other

Infisical

Devops · Security

29,961

The open-source platform for secrets, certificates, privileged access, and AI agent security — all in one self-hostable system.

View details
91
Repo Health
84
Technical
64
Dependency
Built with
TypeScript 96%
Updated 5 days ago
TypeScript
77%
Other

Joplin

Note Taking

56,853

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 6 days ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,338

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
94%
AGPL 3.0

Laudspeaker

Automation · Marketing

2,629

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
45
Repo Health
66
Technical
62
Dependency
Built with
TypeScript 94%
Updated 3 months ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 5 days ago
JavaScript
55%
Other

Lokus

Knowledge Management · Note Taking

829

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
75
Repo Health
75
Technical
64
Dependency
Built with
JavaScript 55%
HTML 21%
Rust 12%
Updated 2 months ago
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

29,041

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
90
Repo Health
73
Technical
65
Dependency
Built with
TypeScript 99%
Updated 5 days ago
TypeScript
88%
Apache 2.0

Medplum

Authentication · Databases · Developer Tools

2,760

An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.

View details
93
Repo Health
90
Technical
71
Dependency
Built with
TypeScript 88%
Updated 5 days ago
TypeScript
87%
MIT

medusa

Ecommerce

36,897

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
94
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers