Can axios serialize FormData consistently across browser and Node.js without manual header management?
0 reputation · 04 Oct 2021, 08:09 UTC
Goal
Achieve identical FormData request serialization in both browser and Node.js runtimes so that a single codebase can run in a repeatable development environment without environment-specific branching.
Constraints and uncertainty
Axios automatically detects FormData in browsers and emits a correct multipart/form-data Content-Type header with boundary. In Node.js, axios does not set this header; the form-data package must be installed separately and its getHeaders() output attached manually. No axios configuration flag bridges this gap, and the behavior may shift between major versions. Mock adapters often fail to reproduce the exact header differences, making local verification unreliable.
Questions
- Which approach—custom adapter, request interceptor, or wrapper utility—provides the most maintainable normalization for isomorphic FormData payloads?
- Does axios 1.x introduce any built-in mechanism to unify this behavior, or is external normalization still required?
- How can a test suite reliably verify identical wire-format output across both runtimes without spinning up a real HTTP server?