ef

express-formidable

An Express middleware of Formidable that just works.

Showing:

Popularity

Downloads/wk

19.3K

GitHub Stars

118

Maintenance

Last Commit

3yrs ago

Contributors

3

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Readme

express-formidable Build Status

An Express middleware of Formidable that just works.

What are Express, Formidable, and this?

Express is a fast, unopinionated, minimalist web framework for Node.js.

Formidable is a Node.js module for parsing form data, including multipart/form-data file upload.

So, express-formidable is something like a bridge between them, specifically an Express middleware implementation of Formidable.

It aims to just work.

Install

npm install express-formidable

How to use

const express = require('express');
const formidableMiddleware = require('express-formidable');

var app = express();

app.use(formidableMiddleware());

app.post('/upload', (req, res) => {
  req.fields; // contains non-file fields
  req.files; // contains files
});

And that's it.

express-formidable can basically parse form types Formidable can handle, including application/x-www-form-urlencoded, application/json, and multipart/form-data.

Option

app.use(formidableMiddleware(opts));

opts are options which can be set to form in Formidable. For example:

app.use(formidableMiddleware({
  encoding: 'utf-8',
  uploadDir: '/my/dir',
  multiples: true, // req.files to be arrays of files
});

For the detail, please refer to the Formidable API.

Events

app.use(formidableMiddleware(opts, events));

events is an array of json with two field:

FieldDescription
eventThe event emitted by the form of formidable. A complete list of all the possible events, please refer to the Formidable Events
actionThe callback to execute. The signature is function (req, res, next, ...formidable_parameters)

For example:

const events = [
  {
    event: 'fileBegin',
    action: function (req, res, next, name, file) { /* your callback */ }
  }, 
  {
    event: 'field',
    action: function (req, res, next, name, value) { /* your callback */ }
  }
];

Error event

Unless an error event are provided by the events array parameter, it will handle by the standard next(error).

Contribute

git clone https://github.com/utatti/express-formidable.git
cd express-formidable
npm install

To lint and test:

npm test

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

formidableThe most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
User Rating
4.5/ 5
4
Top Feedback
2Easy to Use
1Great Documentation
1Performant
GitHub Stars
6K
Weekly Downloads
5M
form-dataA module to create readable `"multipart/form-data"` streams. Can be used to submit forms and file uploads to other web applications.
User Rating
4.8/ 5
4
Top Feedback
2Great Documentation
1Easy to Use
1Performant
GitHub Stars
2K
Weekly Downloads
36M
multerNode.js middleware for handling `multipart/form-data`.
User Rating
4.5/ 5
15
Top Feedback
7Great Documentation
5Easy to Use
5Performant
GitHub Stars
9K
Weekly Downloads
2M
dic
dicerA very fast streaming multipart parser for node.js
User RatingN/A
Top Feedback
N/A
GitHub Stars
160
Weekly Downloads
4M
bus
busboyA streaming parser for HTML form data for node.js
User RatingN/A
Top Feedback
N/A
GitHub Stars
2K
Weekly Downloads
4M
otf
object-to-formdataConvenient JavaScript function that serializes Objects to FormData instances.
User RatingN/A
Top Feedback
N/A
GitHub Stars
267
Weekly Downloads
34K
See 11 Alternatives

Tutorials

No tutorials found
Add a tutorial