Package Manager Installation
Install WebTorrent using your preferred package manager:WebTorrent requires Node.js 16 or higher for server-side usage.
Browser Installation
Using a Bundler (Recommended)
If you’re using a module bundler like Webpack, Vite, or Rollup, simply import WebTorrent after installing it:Using Pre-built Bundle
For webpack users or if you prefer to skip bundler configuration, use the pre-built version:CDN Usage (ES Modules)
You can load WebTorrent directly from a CDN without any build step:Environment-Specific Setup
WebTorrent uses WebRTC for peer-to-peer communication in the browser. Modern browsers support this out of the box:
Important: Browser-based WebTorrent clients can only connect to other WebRTC-enabled peers (“web peers”). They cannot connect to traditional BitTorrent peers using TCP/UDP.
sw.min.js file from the WebTorrent package to your public directoryconst controller = await navigator.serviceWorker.register('./sw.min.js', {
scope: './'
})
await navigator.serviceWorker.ready
client.createServer({ controller })
The standard
webtorrent package in Node.js cannot connect to browser peers. To connect to both traditional peers AND browser peers, use webtorrent-hybrid instead.Command Line Interface
WebTorrent also provides a command-line tool for downloading and streaming torrents:webtorrent command:
WebTorrent Desktop
For a complete desktop application with a GUI, check out WebTorrent Desktop for Mac, Windows, and Linux.
Verify Installation
Test that WebTorrent is installed correctly:Next Steps
Quick Start Guide
Learn the basics with working examples
API Reference
Explore the complete WebTorrent API