1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
const express = require('express') const app = express() const port = 9000 const AdmZip = require('adm-zip'); app.get('/', (req, res) => { const zip = new AdmZip(); zip.addLocalFile("./file1.txt"); zip.addLocalFile("./file2.js"); zip.addLocalFile("./file3.php"); const downloadName = `${Date.now()}.zip`; const data = zip.toBuffer(); res.set('Content-Type','application/octet-stream'); res.set('Content-Disposition',`attachment; filename=${downloadName}`); res.set('Content-Length',data.length); res.send(data); }) app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.
Subscribe
Login
0 Comments