DEV Community

Hassan Nadeem
Hassan Nadeem

Posted on

I built a P2P file sharing tool because I got tired of paying for hosting to share files with friends

The idea
Instead of uploading a file somewhere and having people download it from that server, what if the people downloading it became part of the hosting themselves. You run one command, get a link, send it to someone. They open it and their browser pulls the file straight from yours over WebRTC, no upload step in between. Then the moment they finish downloading, their browser becomes a seeder too. So the next person who opens the link might get it from them instead of you.
npx meshare ./file.mp4
That's the whole command. You get a link and a QR code back.
The part that actually proves the concept
The real test was this. I shared a file, had a second device download it fully, then I closed the original sender's tab completely. A third device opened the same link and still got the file, served entirely by the second device. That's the whole point of the project working in one test.
How it actually works under the hood
WebRTC handles the actual data transfer. PeerJS handles the initial handshake between browsers. For networks that block direct peer connections, like strict school or corporate wifi, it falls back to relaying through a TURN server automatically, and I run a small Cloudflare Worker that mints short lived credentials for that so nothing sensitive sits exposed in the page source.
Seeders register themselves under deterministic slot IDs tied to the file, up to 8 per file. A new person joining just probes those slots and grabs the file from whoever answers first. If a seeder disappears, that slot opens back up for someone else.
It also hosts small sites now
meshare site ./my-game does the same thing but for a folder. Bundles it up, hashes every file so nobody in the mesh can inject bad code, and serves the whole thing peer to peer. Tried it with a small browser game and it opened full screen just like a normal hosted site would.
What I'm being honest about
This isn't a Netlify replacement and I'm not pretending it is. A few real limitations.
If literally everyone who has a file closes their tab at the same exact moment, the file's gone until someone comes back online with it. There's no backup storage behind it right now on purpose, I'd rather add that once real usage shows I actually need it instead of guessing.
Also once a tab is fully closed it stops seeding completely. That's just how browsers handle WebRTC, no way around it with code. Reopening the tab brings it back instantly from local cache though, no re-download needed.
It also depends on a free public signaling server right now, so there's no uptime guarantee there yet.
Try it
It's free, MIT licensed, no signup needed.
npx meshare ./anything
Repo's here if you want to see how the mesh logic or the TURN fallback actually works: github.com/HassanNadeem1122/meshare
Genuinely curious if anyone's tried something similar, or can break it on a network I haven't tested yet.

Top comments (0)