Simple download any file using minimal framework
Requirement
- FileServer
- Node
- Express JS, Express Generator (optional)
- Request API
FileServer Host the file which you want to download. For sake of simplicity I used a Python SimpleHTTP server.
python -m SimpleHTTPServer [port]
python -m SimpleHTTPServer 5000
Express JS
To create the server which interacts with the front-end. In addition to that, makes request to FileServer too.
File: /routes/user.js
router.get('/download', function(req, res) {
var data = null;
request('http://localhost:5000/xxxx.pdf')
.pipe(res.status(200));
});
File: /views/index.jade
h1= title
p Welcome to #{title}
a(href='/users/download' download='filename') download
That's it.
install dependencies: $ cd filetransfer && npm install
run the app: $ DEBUG=filetransfer:* npm start