ItSolutionStuff.com

Multiple File Upload in Node JS using Multer Example

By Hardik Savani β€’ March 23, 2021
Node JS

Hello,

This article is focused on node js express multiple file upload example. you will learn multiple file upload using multer in node js. let’s discuss about node js multer multiple file upload example. let’s discuss about node js multiple file upload using multer. You just need to some step to done node js express multiple file upload example.

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

Preview:

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

app.js

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 + '-' + Date.now() + path.extname(file.originalname));

}

});

var upload = multer({ storage: storage })

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

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

});

app.post('/', upload.array('multi-files'), (req, res) => {

res.redirect('/');

});

app.listen(3000);

Step 4: Create index.html file

index.html

<!DOCTYPE html>

<html lang="en">

<head>

<title>Node js Express Multiple File Upload using Multer Example - ItSolutionStuff.com</title>

<meta charset="UTF-8">

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

</head>

<body>

<h1>Node js Express Multiple File Upload using Multer Example - ItSolutionStuff.com</h1>

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

<input type="file" name="multi-files" multiple>

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

</form>

</body>

</html>

now you can simply run by following command:

npm start

open following url:

localhost:3000

i hope it can help you...

Tags: Node JS
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

File Upload in Node JS using Multer Example

Read Now β†’
β˜…

Node js Express Image Upload using Multer Example

Read Now β†’
β˜…

Four Reasons Why Node.js is your Server-side Hero

Read Now β†’
β˜…

Multiple File Upload in Angular Tutorial

Read Now β†’
β˜…

How to Connect MySQL Database in Node JS?

Read Now β†’
β˜…

Laravel Authenticate User in NodeJS with Socket io using JWT

Read Now β†’
β˜…

Laravel Multiple Files Download with Response Example

Read Now β†’
β˜…

How to Upgrade Node.js Version in Ubuntu?

Read Now β†’
β˜…

How to Use Foreach Object in Node.js?

Read Now β†’
β˜…

Laravel 5.2 chat message module using socket.io, redis, express and nodejs from from scratch.

Read Now β†’