busboy vs formidable vs multer vs express-fileupload vs connect-multiparty vs express-formidable
Node.js File Upload Middleware Comparison
1 Year
busboyformidablemulterexpress-fileuploadconnect-multipartyexpress-formidableSimilar Packages:
What's Node.js File Upload Middleware?

These packages provide middleware solutions for handling file uploads in Node.js applications. They facilitate the parsing of multipart/form-data, which is commonly used for uploading files via HTML forms. Each package has its unique features, performance characteristics, and use cases, making them suitable for different scenarios in web development.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
busboy15,677,2202,903124 kB36--
formidable10,849,8177,102203 kB504 months agoMIT
multer6,437,66711,70927.6 kB269-MIT
express-fileupload376,1181,541116 kB237 months agoMIT
connect-multiparty79,402349-06 years agoMIT
express-formidable45,451132-246 years agoMIT
Feature Comparison: busboy vs formidable vs multer vs express-fileupload vs connect-multiparty vs express-formidable

Performance

  • busboy:

    Busboy is designed for high performance and low memory usage. It streams file uploads directly to disk or memory, allowing for efficient handling of large files without blocking the event loop, making it suitable for high-throughput applications.

  • formidable:

    Formidable provides solid performance for file uploads but may require more configuration to achieve optimal results. It is suitable for applications that need a balance between performance and control over the upload process.

  • multer:

    Multer is highly performant, especially with its built-in storage engines. It allows for efficient handling of file uploads while providing options for file filtering and size limits, making it a versatile choice for many applications.

  • express-fileupload:

    Express-FileUpload is easy to use but may not be optimized for handling very large files. It is best for applications where simplicity and speed of development are prioritized over raw performance.

  • connect-multiparty:

    Connect-Multiparty is relatively lightweight but may not be as performant as Busboy for large file uploads. It is more suited for smaller files and simpler applications, where performance is not the primary concern.

  • express-formidable:

    Express-Formidable offers good performance for handling both files and form data, but its performance may vary depending on the size of the uploads and the complexity of the form data being processed.

Ease of Use

  • busboy:

    Busboy has a steeper learning curve due to its low-level API. It requires a good understanding of streams and may not be the best choice for beginners or those looking for quick implementation.

  • formidable:

    Formidable is more complex than some other options but provides a lot of flexibility. It may require additional effort to set up but is worth it for applications needing detailed control over the upload process.

  • multer:

    Multer is designed to be easy to use, with clear documentation and straightforward configuration options. It is a great choice for developers looking for a balance of ease of use and powerful features.

  • express-fileupload:

    Express-FileUpload is very user-friendly, requiring minimal setup. It allows developers to quickly implement file uploads with just a few lines of code, making it ideal for rapid development.

  • connect-multiparty:

    Connect-Multiparty is straightforward to use and integrates easily with Connect and Express. Its simplicity makes it a good choice for developers who need a quick solution without much overhead.

  • express-formidable:

    Express-Formidable is easy to set up and provides a good balance of features and usability. It is suitable for developers who want to handle both file uploads and form data without much complexity.

File Handling Capabilities

  • busboy:

    Busboy excels at handling streaming uploads, allowing files to be processed as they are received. This is particularly useful for large files and real-time applications where immediate processing is beneficial.

  • formidable:

    Formidable provides comprehensive file handling capabilities, including support for file streams and detailed control over the upload process. It is well-suited for applications that require extensive file management features.

  • multer:

    Multer offers powerful file handling capabilities, including file size limits, filtering, and multiple file uploads. Its flexibility allows developers to customize the upload process to fit their application's needs.

  • express-fileupload:

    Express-FileUpload supports basic file uploads and allows for easy access to uploaded files. However, it may lack some advanced handling capabilities found in more robust libraries.

  • connect-multiparty:

    Connect-Multiparty can handle file uploads but may not support advanced features like streaming or file filtering as effectively as other packages. It is suitable for basic file handling needs.

  • express-formidable:

    Express-Formidable supports both file uploads and regular form data, making it versatile for applications needing to process various input types simultaneously. It handles file streams efficiently, which is a plus.

Integration with Frameworks

  • busboy:

    Busboy can be integrated with any Node.js framework but requires more manual setup compared to middleware solutions. It is best suited for applications that need fine-grained control over the upload process.

  • formidable:

    Formidable can be used independently of any framework, giving developers the flexibility to use it in various contexts. However, it may require additional setup for integration with Express or other frameworks.

  • multer:

    Multer is designed for Express applications, providing excellent integration and support for multipart/form-data. It is the go-to choice for developers using Express who need robust file upload capabilities.

  • express-fileupload:

    Express-FileUpload is built specifically for Express, ensuring seamless integration and straightforward usage within Express applications. It is ideal for developers looking for a quick and easy solution for file uploads in Express.

  • connect-multiparty:

    Connect-Multiparty is specifically designed for use with Connect and Express, making it easy to integrate into applications built with these frameworks. It is a good choice for developers already using these technologies.

  • express-formidable:

    Express-Formidable is tailored for Express, providing a simple way to handle file uploads alongside regular form data. Its integration is smooth and requires minimal configuration.

Community and Support

  • busboy:

    Busboy has a smaller community compared to some other packages, which may result in fewer resources and examples available for troubleshooting and support.

  • formidable:

    Formidable has been around for a while and has a solid community, providing ample resources and support for developers using the library.

  • multer:

    Multer has a large and active community, with plenty of resources, examples, and support available, making it a reliable choice for developers.

  • express-fileupload:

    Express-FileUpload has a growing community and good documentation, making it easier for developers to find help and resources when needed.

  • connect-multiparty:

    Connect-Multiparty has a moderate community presence, but it may not be as actively maintained as other options, which could affect long-term support.

  • express-formidable:

    Express-Formidable benefits from a supportive community and clear documentation, making it easier for developers to implement and troubleshoot issues.

How to Choose: busboy vs formidable vs multer vs express-fileupload vs connect-multiparty vs express-formidable
  • busboy:

    Choose Busboy if you need a lightweight, fast solution for streaming file uploads. It is particularly useful for handling large files and provides a low-level API for processing streams, making it ideal for applications where performance is critical.

  • formidable:

    Choose Formidable if you prefer a standalone library that can be used outside of Express. It offers a comprehensive set of features for handling file uploads and is particularly useful for applications that require more control over the file upload process.

  • multer:

    Select Multer if you need a powerful and flexible middleware specifically designed for handling multipart/form-data. It provides extensive configuration options, including storage engines and file filtering, making it ideal for applications that require complex file upload handling.

  • express-fileupload:

    Opt for Express-FileUpload if you want a simple and easy-to-use middleware that allows for quick file uploads with minimal configuration. It supports file size limits and is suitable for smaller projects or when you need to get up and running quickly.

  • connect-multiparty:

    Select Connect-Multiparty if you are using Connect or Express and require a simple, straightforward solution for handling file uploads. It is easy to set up and works well for basic use cases, but may lack advanced features compared to other options.

  • express-formidable:

    Use Express-Formidable if you need a robust solution that can handle both file uploads and regular form data. It supports file streaming and is well-suited for applications that require handling various types of input data alongside file uploads.

README for busboy

Description

A node.js module for parsing incoming HTML form data.

Changes (breaking or otherwise) in v1.0.0 can be found here.

Requirements

Install

npm install busboy

Examples

  • Parsing (multipart) with default options:
const http = require('http');

const busboy = require('busboy');

http.createServer((req, res) => {
  if (req.method === 'POST') {
    console.log('POST request');
    const bb = busboy({ headers: req.headers });
    bb.on('file', (name, file, info) => {
      const { filename, encoding, mimeType } = info;
      console.log(
        `File [${name}]: filename: %j, encoding: %j, mimeType: %j`,
        filename,
        encoding,
        mimeType
      );
      file.on('data', (data) => {
        console.log(`File [${name}] got ${data.length} bytes`);
      }).on('close', () => {
        console.log(`File [${name}] done`);
      });
    });
    bb.on('field', (name, val, info) => {
      console.log(`Field [${name}]: value: %j`, val);
    });
    bb.on('close', () => {
      console.log('Done parsing form!');
      res.writeHead(303, { Connection: 'close', Location: '/' });
      res.end();
    });
    req.pipe(bb);
  } else if (req.method === 'GET') {
    res.writeHead(200, { Connection: 'close' });
    res.end(`
      <html>
        <head></head>
        <body>
          <form method="POST" enctype="multipart/form-data">
            <input type="file" name="filefield"><br />
            <input type="text" name="textfield"><br />
            <input type="submit">
          </form>
        </body>
      </html>
    `);
  }
}).listen(8000, () => {
  console.log('Listening for requests');
});

// Example output:
//
// Listening for requests
//   < ... form submitted ... >
// POST request
// File [filefield]: filename: "logo.jpg", encoding: "binary", mime: "image/jpeg"
// File [filefield] got 11912 bytes
// Field [textfield]: value: "testing! :-)"
// File [filefield] done
// Done parsing form!
  • Save all incoming files to disk:
const { randomFillSync } = require('crypto');
const fs = require('fs');
const http = require('http');
const os = require('os');
const path = require('path');

const busboy = require('busboy');

const random = (() => {
  const buf = Buffer.alloc(16);
  return () => randomFillSync(buf).toString('hex');
})();

http.createServer((req, res) => {
  if (req.method === 'POST') {
    const bb = busboy({ headers: req.headers });
    bb.on('file', (name, file, info) => {
      const saveTo = path.join(os.tmpdir(), `busboy-upload-${random()}`);
      file.pipe(fs.createWriteStream(saveTo));
    });
    bb.on('close', () => {
      res.writeHead(200, { 'Connection': 'close' });
      res.end(`That's all folks!`);
    });
    req.pipe(bb);
    return;
  }
  res.writeHead(404);
  res.end();
}).listen(8000, () => {
  console.log('Listening for requests');
});

API

Exports

busboy exports a single function:

( function )(< object >config) - Creates and returns a new Writable form parser stream.

  • Valid config properties:

    • headers - object - These are the HTTP headers of the incoming request, which are used by individual parsers.

    • highWaterMark - integer - highWaterMark to use for the parser stream. Default: node's stream.Writable default.

    • fileHwm - integer - highWaterMark to use for individual file streams. Default: node's stream.Readable default.

    • defCharset - string - Default character set to use when one isn't defined. Default: 'utf8'.

    • defParamCharset - string - For multipart forms, the default character set to use for values of part header parameters (e.g. filename) that are not extended parameters (that contain an explicit charset). Default: 'latin1'.

    • preservePath - boolean - If paths in filenames from file parts in a 'multipart/form-data' request shall be preserved. Default: false.

    • limits - object - Various limits on incoming data. Valid properties are:

      • fieldNameSize - integer - Max field name size (in bytes). Default: 100.

      • fieldSize - integer - Max field value size (in bytes). Default: 1048576 (1MB).

      • fields - integer - Max number of non-file fields. Default: Infinity.

      • fileSize - integer - For multipart forms, the max file size (in bytes). Default: Infinity.

      • files - integer - For multipart forms, the max number of file fields. Default: Infinity.

      • parts - integer - For multipart forms, the max number of parts (fields + files). Default: Infinity.

      • headerPairs - integer - For multipart forms, the max number of header key-value pairs to parse. Default: 2000 (same as node's http module).

This function can throw exceptions if there is something wrong with the values in config. For example, if the Content-Type in headers is missing entirely, is not a supported type, or is missing the boundary for 'multipart/form-data' requests.

(Special) Parser stream events

  • file(< string >name, < Readable >stream, < object >info) - Emitted for each new file found. name contains the form field name. stream is a Readable stream containing the file's data. No transformations/conversions (e.g. base64 to raw binary) are done on the file's data. info contains the following properties:

    • filename - string - If supplied, this contains the file's filename. WARNING: You should almost never use this value as-is (especially if you are using preservePath: true in your config) as it could contain malicious input. You are better off generating your own (safe) filenames, or at the very least using a hash of the filename.

    • encoding - string - The file's 'Content-Transfer-Encoding' value.

    • mimeType - string - The file's 'Content-Type' value.

    Note: If you listen for this event, you should always consume the stream whether you care about its contents or not (you can simply do stream.resume(); if you want to discard/skip the contents), otherwise the 'finish'/'close' event will never fire on the busboy parser stream. However, if you aren't accepting files, you can either simply not listen for the 'file' event at all or set limits.files to 0, and any/all files will be automatically skipped (these skipped files will still count towards any configured limits.files and limits.parts limits though).

    Note: If a configured limits.fileSize limit was reached for a file, stream will both have a boolean property truncated set to true (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.

  • field(< string >name, < string >value, < object >info) - Emitted for each new non-file field found. name contains the form field name. value contains the string value of the field. info contains the following properties:

    • nameTruncated - boolean - Whether name was truncated or not (due to a configured limits.fieldNameSize limit)

    • valueTruncated - boolean - Whether value was truncated or not (due to a configured limits.fieldSize limit)

    • encoding - string - The field's 'Content-Transfer-Encoding' value.

    • mimeType - string - The field's 'Content-Type' value.

  • partsLimit() - Emitted when the configured limits.parts limit has been reached. No more 'file' or 'field' events will be emitted.

  • filesLimit() - Emitted when the configured limits.files limit has been reached. No more 'file' events will be emitted.

  • fieldsLimit() - Emitted when the configured limits.fields limit has been reached. No more 'field' events will be emitted.