16

Am new to Node world.

UseCase :

Was having a simple scenario of uploading XLS files on Angular front, process them on Node, make some manipulations and then save JSON on to Mongo DB.

After receiving files from Angular, i was searching what is the best way to parse / process a file on Node and then came across articles on these famous node modules - multer, multiparty and connect-multiparty.

Every article explains how to use corresponding module and couldn't find any one telling which one to be used when.

I found that multer is mainly used when you are trying to save a file on Disk Storage and that doesn't suffice my use case.

So should i ignore multer or actually use it ?

When should i actually use multiparty and connect-multiparty ?

BeingSuman
  • 3,015
  • 7
  • 30
  • 48

2 Answers2

14

You can categorize the available file processing libraries into three categories: are they standalone or Express.js-specific, do they store intermediate files or use streams, and if the intermediate files are stored in temporary directory or in memory.

Standalone parsers like busboy can be used with or without Express.js. On the other hand Express.js middlewares augment the request object by adding req.files that you can conveniently access the files. Some implementations store intermediate files either in temp directory or in memory. Others let you access stream of uploaded file contents without busting the server's memory or hard disk.

Depending on your situation, ask these questions in order to determine which library suits you best.

  • do you need Express.js or not?
  • is saving intermediate files ok, or do you want to stream the files?
  • if saving intermediate files is alright, would you prefer them in memory or on hard disk?

Then pick one from the list of most used file upload processing libraries using this decision tree. The decision tree is from the article:

Choose between Formidable, Busboy, Multer and Multiparty for processing file uploads

Choose between Formidable, Busboy, Multer and Multiparty for processing file uploads

pspi
  • 11,189
  • 1
  • 20
  • 18
  • Great answer, but where does mutliparty go in this flowchart? – devuxer Sep 25 '21 at 21:11
  • Followup - referring to the original article, it looks like the answer to my question above is that multiparty falls into pretty much the same category as busboy, except busboy is faster, so why bother with Multiparty? (I don't necessarily agree that speed is the only criteria (what about ease of use, documentation, security, etc.?), but that explains why it doesn't show up in the flowchart.) – devuxer Sep 25 '21 at 22:10
13

This question lists some of the options:

How could I upload files in ExpressJS 4.x

There are modules to parse multiform data directly, and express middleware built on top of these.

The top three modules by Github stars for parsing directly are node-formidable (3376), busboy (814), node-multiparty (557).

The top middleware is multer (built on busboy, 2515 stars). connect-multiparty has a note suggesting not to use it. connect-busboy has not been updated in four years.

Just based on this I'd suggest node-formidable, busboy, or multer if you want Express middleware.

Also note that multer has a MemoryStorage memory storage engine.

mega6382
  • 9,211
  • 17
  • 48
  • 69
Simon D
  • 4,150
  • 5
  • 39
  • 47
  • Hi Simon. I know I am late to the party, but is formidable still updated and used? Looks like multer is trending now in every other "image upload" tutorial. Is formidable still safe to use? Thanks – slevin Sep 14 '18 at 22:59
  • Don't really follow this, but looking at https://github.com/felixge/node-formidable/issues/412 it looks like they've just added a couple of maintainers for formidable. I guess it will work OK. Multer seems to be updated more regularly (last update 19 days ago), but is middleware rather than direct parser. – Simon D Sep 16 '18 at 09:54