Skip to content

Instantly share code, notes, and snippets.

@zentala
Last active January 1, 2023 19:21
Show Gist options
  • Save zentala/e2d484472961feb805675b8aef1db8ad to your computer and use it in GitHub Desktop.
Save zentala/e2d484472961feb805675b8aef1db8ad to your computer and use it in GitHub Desktop.
Node & Express file downloading in 4 lines!
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