WebTorrent is a versatile streaming BitTorrent client designed for both Node.js environments and web browsers. Currently stable at version 2.8.5, it receives frequent minor updates and bug fixes, with new features introduced periodically. Its primary differentiator is its ability to operate directly within a web browser using WebRTC data channels for peer-to-peer communication, making it the "streaming torrent client for the web." In Node.js, it functions as a standard torrent client utilizing TCP and UDP. This pure JavaScript library exposes torrent files as streams, supporting on-demand piece fetching, and can seamlessly switch between sequential and rarest-first piece selection strategies. WebTorrent facilitates connecting "web peers" (browser clients) with other WebTorrent-compatible clients, including desktop applications and specialized command-line tools like `webtorrent-hybrid`.
npm install webtorrentVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a WebTorrent client, adds a magnet URI, logs download progress, and saves the torrent's files to a local directory once complete. It includes error handling and proper client cleanup.
Update imports to use ES module syntax: `import WebTorrent from 'webtorrent'`.
Upgrade your Node.js environment to version 16 or higher.
Use `await file.arrayBuffer()` to get an `ArrayBuffer` or `file.stream()` to get a `ReadableStream` instead.
Ensure the torrent you are trying to download/seed in the browser is being seeded by a WebRTC-capable client (e.g., WebTorrent Desktop, Instant.io, webtorrent-hybrid).
Always call `torrent.destroy()` when you are finished with a torrent to clean up its associated storage.
Ensure the server hosting the .torrent file has `Access-Control-Allow-Origin` headers configured to permit requests from your domain.
Verify that the torrent is being seeded by a client that supports WebTorrent/WebRTC (e.g., WebTorrent Desktop, instant.io).
Double-check the magnet URI, info hash, or URL for correctness and ensure it adheres to the specified formats. For Node.js, file paths and Buffers are also accepted.
Ensure the target download directory (specified in `client.add({ path: './downloads' })`) has appropriate write permissions for the Node.js process. Try using a different, accessible directory or running the process with elevated privileges if necessary.No dependency data recorded yet.