Node js Express Image Upload using Multer Example

By Hardik Savani March 20, 2021 Category : Node JS


In this tute, we will discuss node js express image upload example multer. if you want to see example of node.js express upload image example then you are a right place. i would like to show you node js image upload using multer. We will use node.js image uploading with multer. Let's see bellow example node.js multer upload image.

I will give you step by step simple example of image upload using multer with node js and express js. let's follow bellow steps:


Step 1: Create Node App

run bellow command and create node app.

mkdir my-app

cd my-app

npm init

Step 2: Install express and multer

run bellow command and create node app.

npm install express multer --save

Step 3: Create app.js file


const express = require('express');

const multer = require('multer');

const path = require('path');

const app = express();

const storage = multer.diskStorage({

destination: function(req, file, cb) {

cb(null, 'uploads/');


filename: function(req, file, cb) {

cb(null, file.fieldname + '-' + + path.extname(file.originalname));



var upload = multer({ storage: storage })

app.get('/', (req, res) => {

res.sendFile(__dirname + '/index.html');

});'/', upload.single('file-to-upload'), (req, res) => {




Step 4: Create index.html file


<!DOCTYPE html>

<html lang="en">


<title>Node js Express File Upload using Multer Example -</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">



<h1>Node js Express File Upload using Multer Example -</h1>

<form action="/" enctype="multipart/form-data" method="post">

<input type="file" name="file-to-upload">

<input type="submit" value="Upload">




now you can simply run by following command:

npm start

open following url:


i hope it can help you...

Tags :