How to Upload File in Node.js

Nowadays I am doing work on a chat app, which is in Node.js and the big problem is that I’m absolutely fresher in Node. I even do not know how to upload a picture in Node. Then I did google search and after spending much time I have not found a perfect result.Then I got some idea from 3-4 websites and created perfect code for file uploding .
So below I’m gonna tell you how you can upload file using Node

I am going to use express framework and middleware called “multer”. This middleware is designed for handling the multipart/form-data.

Installing dependency

Save the package.json in folder and type

to install the required stuff.
This code is updated with latest version of Multer.


Run project:

to run the project. Visit localhost:3000 to view the app. Select the file and check the uploads folder. Your file must be present there!
After completing upload , req.files variable holds following array of information.

Hope it will Help You and please subscribe me and like my facebook page :

and make me proud.By the way if you face any problem then let me know in comment section below

Leave a Reply

Your email address will not be published. Required fields are marked *