Basic Concepts
Before diving in, let’s understand the key components:- Client - The main WebTorrent instance that manages all torrents
- Torrent - Represents a torrent being downloaded or seeded
- File - Individual files within a torrent
- Peer - Other clients you’re connected to
Your First Torrent Download
Let’s download a file using WebTorrent. This example works in both Node.js and the browser.Complete Examples
- Browser - Video Streaming
- Browser - File Upload
- Node.js - Download
- Node.js - Seed Files
Stream a video torrent directly in the browser:
Make sure to copy
sw.min.js from node_modules/webtorrent/dist/sw.min.js to your public directory.Working with Files
Getting File Data
WebTorrent provides multiple ways to access file data:Streaming to a Video Element
In the browser, you can stream directly to a<video> or <audio> element:
Monitoring Progress
Track download progress and stats in real-time:Event Handling
WebTorrent uses events to notify you of important changes:Configuration Options
Customize the client and torrent behavior:Common Patterns
Pausing and Resuming
Selective File Download
Destroying Torrents
Cleanup
Always destroy the client when you’re done:Next Steps
Browser Usage
Learn about browser-specific features and setup
Node.js Usage
Explore Node.js specific capabilities
API Reference
Dive into the complete API documentation
Examples
See more real-world examples and use cases