1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| const express = require('express'); const app = express(); const port = 3000;
app.get('/download', (req, res) => { const data = "Hello, this is some text data!"; const blob = Buffer.from(data, 'utf-8');
res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Disposition', 'attachment; filename=data.txt'); res.send(blob); });
app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); });
|