Last active
January 1, 2023 19:21
-
-
Save zentala/e2d484472961feb805675b8aef1db8ad to your computer and use it in GitHub Desktop.
Node & Express file downloading in 4 lines!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require('express')() | |
const path = require('path') | |
const filePath = path.join(__dirname, 'raport.csv') | |
app.get('/', (req, res) => res.download(filePath)) | |
app.listen(3000, () => console.log(`Server listening on port 3000!`)) | |
// 1) Locate `node simpleDownloadServer.js` and `raport.csv` in the same directory | |
// 2) Execute in console `npm init && npm install express`, and then `node simpleDownloadServer.js` | |
// 3) Open in browser `http://localhost:3000/` in order to download `raport.csv` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment