File Upload With Multer in Node.js and Express

When a web client uploads a file to a server, it is generally submitted through a form and encoded as multipart/form-data. Multer is middleware for Express and Node.js that makes it easy to handle this multipart/form-data when your users upload files. 

In this tutorial, I’ll show you how to use the Multer library to handle different file upload situations in Node.

How Does Multer Work?

As I said above, Multer is Express middleware. Middleware is a piece of software that connects different applications or software components. In Express, middleware processes and transforms incoming requests to the server. In our case, Multer acts as a helper when uploading files.

Project Setup

We will be using the Node Express framework for this project. Of course, you’ll need to have Node installed. 

Create a directory for our project, navigate into the directory, and issue npm init to create a .json file that manages all the dependencies for our application.

mkdir upload-express
cd  upload-express
npm init

Next, install Multer, Express, and the other dependencies necessary to bootstrap an Express app.

npm install express multer body-parser --save

Read full tutorial at code.tutsplus