Uploading files in NodeJS & Express 4 using Formidable

NodeJS is my new love. And Express is one of the best (not to mention most popular) web frameworks. I started learning Node a couple of months ago, and Express v3 was my de facto choice. However, since I’ve started working on one of mymost ambitious projects, Express 4 was about to be released. Since all of my code was written for and tested on version 3, I was wondering if it would work on 4; surprisingly, with just a few changes, it worked fine. However, one of the biggest things that broke was file upload functionality.

Multipart uploads depended on the bodyParser module of Express. However, in version 4, most modules (including bodyParser) were broken out into standalone modules for easy maintainability of the codebase. And this broke uploads. While I was looking for modules that could handle multipart forms, I stumbled upon formidable.

Here’s a quick and dirty example that shows you how to upload files using formidable in Express 4.

Comments Off on Uploading files in NodeJS & Express 4 using Formidable