Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • PDF Invoice Generator
Menu

Node.js Express Tutorial to Download Multiple Files at Once Using express-zip Library in Javascript

Posted on January 19, 2023

 

 

Welcome folks today in this blog post we will be downloading multiple files at once using express-zip library in browser using node.js and express in javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to initialize a new node.js project using the below command

 

 

npm init -y

 

 

npm i express

 

 

npm i express-zip

 

 

Now we need to make the index.js file and copy paste the following code

 

 

index.js

 

 

1
2
3
4
5
6
7
8
9
10
11
var app = require('express')();
let zip = require('express-zip')
 
app.get('/', function(req, res) {
  res.zip([
    { path: 'file1.pdf', name: 'file1.pdf' },
    { path: 'file2.pdf', name: 'file2.pdf' }
  ]);
});
 
app.listen(3000);

 

 

As you can see we are importing the express and express-zip libraries at the top and then we are making the get route at the / homepage and inside it we are using the zip() method inside which we are passing the array of files in which we have two properties in which we are passing the path of the file and then we are passing the filename of the file to be compressed and then we are starting the node.js and express at port 3000.

 

 

 

 

Recent Posts

  • Build a Fixed Deposit Interest Calculator Using Amount and Time in Browser Using HTML5 & Javascript
  • How to Download Files From URL in Node.js Using Node-Downloader-Helper Library
  • Angular 10 Image Carousel and Video Gallery Lightbox Modal Slider Using ng-image-slider Library
  • React Unsplash Api Photo Search App
  • React Form Validation Using Formik and Yup
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • javascript
  • Koajs
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme