Whether you are building an automated backup system or a user-facing download feature, downloading ZIP files from Amazon S3 using Node.js is a fundamental skill. Because Node.js handles data in chunks, you can efficiently process large archives without crashing your server’s memory.
import { PassThrough } from 'stream'; import archiver from 'archiver'; async function streamMultipleFilesAsZip(bucket, fileKeys, outputStream) { const archive = archiver('zip', { zlib: { level: 9 } }); archive.pipe(outputStream); for (const key of fileKeys) { const command = new GetObjectCommand({ Bucket: bucket, Key: key }); const response = await s3Client.send(command); // Append individual file streams to the archive archive.append(response.Body, { name: key.split('/').pop() }); } await archive.finalize(); } Use code with caution. 3. Using Specialized Libraries download zip file from s3 bucket nodejs
This approach fetches each file as a stream and appends it to a "virtual" ZIP archive. javascript Whether you are building an automated backup system