Reputation: 301
I'd like to let another user download a file from my local machine (mac), preferably using http
protocol. I recently learned about streams in node.js and it seems like an interesting project to set up my server locally and stream some big file to another computer (more than 1 GB). I know how to set up a server but because the files are hosted locally how can I pull this off using node? What would be the prerequisites and steps for such a project?
Upvotes: 2
Views: 2753
Reputation: 56
If you're hosting files on one machine and making them available using Node, I would recommend using express, as it is every easy to use.
Using express, hosting files would look something like this:
const express = require('express');
const app = express();
app.use('/', express.static('./files')); // replace ./files with the path to the directory holding the file/files you want to make available
app.listen(80); // :80 is default http port
However if you're looking to use actual streams with Node's native http
module, give this a look.
Upvotes: 2