Image upload using Multer in Node
Published in
3 min readJan 29, 2020
What is Multer?
Multer is a middle that we used for handling multipart/form-data, which is primarily used for uploading files.
As mention, the basic use of multer is to upload files.
Example of image upload using multer :
Step 1 → Initiate package.json using the command
Step 2 → Installation of required npm packages
Step 3 → Add a command in script key of package.json file to run the nodemon server
This is the command that we are going to add
Updated package.json file will look like this
Step 4 → Create app.js file in the same directory where you have initialize the package.json
- Import all the npm packages
- Initiate the express npm package
- Initiate the body-parser npm package using express
- Select a port number and app will listen to that port
- Create a folder with name uploads in the same directory and let multer know where to store the files
- Create a post api using express but before that let store the multer storage location
- Complete app.js file will look like this
Step 5 → Start the nodemon with the following command
Step 6 → Open postman application and create a new post request
- Enter this URL → http://localhost:3000/uploadfile
- Goto Body then form-data
- Give key name as myfile and when you hover over the key is will show a dropdown in which you have to select File
- Then in value you will see a Select Files button, use that button to select any image and send the request
- When uploading is done, you will see a JSON response
This is the basic program you can follow to make your first application for uploading images using multer in nodejs.
This is the github link for the project if you have any doubt.
https://github.com/yash0307jain/Image-Upload---Using---Multer