File Upload in Node JS using Multer Example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother,

In this lesson you will learn node js express file upload lesson multer. i explained simply about node.js express upload file lesson. This tutorial will give you simple lesson of node js file upload using multer. i would like to share with you node.js file uploading with multer.

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

Lesson 1: Create Node App

run bellow command and create node app.

mkdir my-app

cd my-app

npm init

Lesson 2: Install express and multer

run bellow command and create node app.

npm install express multer --save

Lesson 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) => {




Lesson 4: Create index.html file


<!DOCTYPE html>

<html lang="en">


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

<meta charset="UTF-8">

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



<h1>Node js Express File Upload using Multer Lesson -</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:


thank you very much for following up with me.


Recent Posts

Related Posts