This guide will walk you through sharing a file between two peers in just a few minutes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/low-level-js/p2p-file-share/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, make sure you have:- Node.js v22 or higher installed
- The p2p-file-share repository cloned
- A test file to share (or create one)
Quick Setup
Create a test file
First, create a test file to share between peers:Or use any existing file you want to share.
Start the seed node
In your first terminal, start a seed node that has the complete file:You should see output like:
The seed node calculates the SHA-1 hash of the file automatically. This hash will be used to verify file integrity after download.
Start the leecher node
In a second terminal, start a leecher node that will download the file:You should see the download progress:
What Just Happened?
Here’s what occurred behind the scenes:- Handshake: The leecher connected to the seed and exchanged metadata (file name, size, hash, piece size)
- Bitfield: The seed announced it has all pieces of the file
- Request: The leecher requested piece 0
- Piece: The seed sent the piece data (encoded in base64)
- Verification: The leecher verified the complete file’s SHA-1 hash matches the seed’s hash
Next Steps
Now that you have a basic P2P network running, try these next:Add More Peers
Set up a 3+ peer network to see true P2P file distribution
Command Reference
Learn about all available command-line options
Protocol Details
Understand the messaging protocol in depth
Architecture
Learn how the P2P system is designed
Larger Files
For larger files, you’ll see more detailed progress tracking:Files are automatically split into 64 KiB (65536 bytes) pieces. For files smaller than 64 KiB, the piece size adjusts to match the file size.