How to ZIP file and download using Node.js stream

I am just entering the open-source world by trying to contribute to nocodb, an open-source alternative for Airtable. So I tried to build a prototype server that zips files and enables clients to download using Node.js. After some research, this is what I came up with.

First, let’s install the packages that we need. Archiver is a streaming interface for archiving, while base64-stream enables us to convert Node.js Buffer to base64 encoding with stream. Using stream allows us to prevent loading too much data into memory when we are creating zip files.

Now let’s create a file called server.js.

Then we will add a file called index.html to the root folder.

Lastly, let’s create a folder called files and add files to it. Then we are all set. Visit http://localhost:8888 and click the button to download the zip file.

weird-cat weird-cat