Hello friends, previously we tried to upload a file using PHP, Java (JSP), but in this post we are going to learn how to upload a file using Node JS. Its very simple to upload file using Node JS than other scripting languages or technologies. In this post we will focus on following topics, How can we upload a file in Node JS Modules requirement for uploading file Steps to upload file in Node JS

How can we upload a file in Node JS :

Like other programming language and technology, there are some pre-defined modules are available to upload file from client to sever. But in this post we will use the module named as multer to upload file. So multer is basically a module available for Node to upload file from client's browser to server.

Modules requirement for uploading file :

Following are the module, we will use for some specific functionalities,

express -------------> for routing, creating and listening the server

multer --------------> for uploading the file

Steps to upload file in Node JS :

Following are the step by step procedure to upload file in Node JS,

Step 1: (Installing the required modules)

In this step, we need to install the required modules, such as express and multer. Just open your Command Prompt and type following commands to have the required modules for our application.

> npm install express (to install express)

and

> npm install multer (to install multer)

Step 2: (Attach the required modules)

In this step we will start coding. So now we will attach the required modules, by writing following piece of code,

var express = require('express');
var multer   = require('multer');