简体   繁体   中英

How to share local files between two computers using node.js?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM