ββββ β ββββββ βββββββ ββββββ β βββββββββββ
ββ ββ β ββββ βββββββ βββββ β βββ β ββββ βββ ββ
βββ ββ βββββββ ββββββ ββββββ βββ β ββ β ββββ ββ
ββββ ββββββββ βββββββ ββββ β βββ β ββ β ββββ β
ββββ βββββ ββββββββββββββ βββββββββββββββ ββββ β
β ββ β β β ββββββ βββ β ββ ββ ββ βββ β β ββ
β ββ β ββ β β ββ β β β β β β β β β β
β β β β β β β β β β β β β β
β β β β β β β
A powerful, feature-rich Node.js CLI wrapper for WebTorrent with real-time progress tracking, peer statistics, and beautiful terminal UI.
- Features
- Architecture
- Project Structure
- Installation
- Usage
- How It Works
- Configuration
- Development
- Troubleshooting
- Contributing
- License
- π Fast Downloads: Leverages WebTorrent protocol for efficient P2P file sharing
- π Real-time Progress: Beautiful CLI progress bar with live statistics
- π₯ Peer Tracking: Monitor connected peers in real-time
- π Speed Metrics: Track download speed with auto-formatted units (B/s, KB/s, MB/s, GB/s)
- β±οΈ ETA Calculation: Smart time estimation with human-readable format
- π¨ Animated Spinner: Visual feedback during torrent initialization
- β Magnet URL Validation: Built-in validation for magnet links
- π Auto-formatting: Intelligent size and speed formatting
- π Node.js 22 LTS: Built for the latest Node.js LTS version
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERFACE β
β (Terminal/CLI Input) β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β server.js (Entry) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Readline Interface for User Input β β
β β β’ Magnet URL Validation β β
β β β’ Initiates Download Process β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT MODULE (src/client) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β WebTorrent Client Manager β β
β β β’ Initialize WebTorrent instance β β
β β β’ Add torrent from magnet URI β β
β β β’ Monitor download events β β
β β β’ Update progress bar β β
β β β’ Handle completion/errors β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β UTILITIES MODULE (src/utils) β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β FORMATTERS β β LOADERS β β LOGGER β β
β ββββββββββββββββ€ ββββββββββββββββ€ ββββββββββββββββ€ β
β β β’ formatETA β β β’ Spinner β β β’ log() β β
β β β’ formatSize β β Animation β β β’ error() β β
β β β’ formatSpeedβ β β’ Progress β β β’ info() β β
β β β’ getDisplay β β Indicator β β β β
β β Format β β β β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
β ββββββββββββββββ β
β β VALIDATORS β β
β ββββββββββββββββ€ β
β β β’ isValid β β
β β MagnetURL β β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WEBTORRENT LIBRARY β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ DHT (Distributed Hash Table) β β
β β β’ Peer Discovery & Connection β β
β β β’ Piece Management β β
β β β’ File System Operations β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FILE SYSTEM (./downloads) β
β Downloaded Torrent Files β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββ
β User β
β Input β
ββββββ¬ββββββ
β Magnet URI
βΌ
βββββββββββββββββββ
β Validator ββββββββΊ Validate Format
ββββββ¬βββββββββββββ
β Valid URI
βΌ
βββββββββββββββββββ
β Spinner ββββββββΊ "Initializing..."
β Animation β
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β WebTorrent β
β Client Init β
ββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββ
β Add Torrent ββββββββΊ Connect to Peers
ββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Download Event Loop β
β βββββββββββββββββββββββββββββββββββββ β
β β 1. Get torrent stats β β
β β 2. Format data (size, speed, ETA)β β
β β 3. Update progress bar β β
β β 4. Check completion β β
β βββββββββββββββββββββββββββββββββββββ β
ββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Download β
β Complete ββββββββΊ Exit Process
βββββββββββββββββββ
nodeWT/
β
βββ π server.js # Entry point - CLI interface
β βββ Handles user input and initiates download
β
βββ π src/
β βββ π client/
β β βββ π index.js # WebTorrent client manager
β β βββ startDownload() # Main download orchestrator
β β βββ Progress tracking # Real-time statistics
β β βββ Event handlers # Download/error events
β β
β βββ π utils/
β βββ π index.js # Utility exports aggregator
β β
β βββ π formatters/
β β βββ π index.js # Data formatting utilities
β β βββ formatETA() # Time formatting (s/m/h/d/w/y)
β β βββ formatSize() # Size formatting (B/KB/MB/GB)
β β βββ formatSpeed() # Speed formatting (B/s β GB/s)
β β βββ getDisplayFormat() # Progress bar template
β β
β βββ π loaders/
β β βββ π index.js # Loading animations
β β βββ updateSpinner() # Animated spinner
β β
β βββ π logger/
β β βββ π index.js # Console logging wrapper
β β βββ log() # Standard output
β β βββ error() # Error output
β β βββ info() # Info output
β β
β βββ π validators/
β βββ π index.js # Input validation
β βββ isValidMagnetURL() # Magnet link validator
β
βββ π downloads/ # Downloaded files destination
β
βββ π package.json # Project dependencies & scripts
βββ π package-lock.json # Locked dependency versions
βββ π .nvmrc # Node version specification (22)
βββ π README.md # This file
| Module | Purpose | Key Functions |
|---|---|---|
| server.js | Entry point & user interaction | promptUser() |
| client/index.js | Torrent management | startDownload() |
| formatters | Data presentation | formatETA(), formatSize(), formatSpeed() |
| loaders | Visual feedback | updateSpinner() |
| logger | Console output | log(), error(), info() |
| validators | Input validation | isValidMagnetURL() |
- Node.js: Version 22.0.0 or higher (LTS recommended)
- npm: Comes with Node.js
- Operating System: Windows, macOS, or Linux
-
Clone or Download the Repository
git clone <repository-url> cd nodeWT
-
Install Dependencies
npm install
-
Verify Installation
node --version # Should show v22.x.x
-
Start the Application
npm start
-
Enter Magnet URL
Please paste your magnetURI: magnet:?xt=urn:btih:... -
Monitor Progress
[ββββββββββββββββββββ] 75% | Peers: 12 | D: 750.45 MB @ 2.5 MB/s | T: 1.0 GB | ETA: 2 minutes
$ npm start
> [email protected] start
> cross-env NODE_NO_WARNINGS=1 node server.js
Please paste your magnetURI:
magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10
/|\- Initializing torrent client & verifying data... -|\/
Torrent is downloading...
Progress
[ββββββββββββββββββββ] 100% | Peers: 15 | D: 1.0000 GB @ 3.2 MB/s | T: 1.0000 GB | ETA: 0 seconds
Torrent download finished ![ββββββββββββββββββββ] 75% | Peers: 12 | D: 750.45 MB @ 2.5 MB/s | T: 1.0 GB | ETA: 2 minutes
βββββββ¬βββββββ β β β β β ββββ Time remaining
β β β β β ββββββββββββββββ Total file size
β β β β ββββββββββββββββββββββββββββ Download speed
β β β βββββββββββββββββββββββββββββββββββββββββ Downloaded amount
β β βββββββββββββββββββββββββββββββββββββββββββββββββββββ Connected peers
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Progress percentage
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Visual progress bar
User Input β Validation β Spinner Animation β WebTorrent Client Init
Magnet URI β DHT Lookup β Peer Discovery β Establish Connections
βββββββββββββββββββββββββββββββββββββββ
β Download Event (triggered by WT) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Extract Torrent Statistics: β
β β’ downloaded (bytes) β
β β’ length (total bytes) β
β β’ downloadSpeed (bytes/sec) β
β β’ timeRemaining (ms) β
β β’ progress (0-1) β
β β’ numPeers (count) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Format Data: β
β β’ formatSize(downloaded) β
β β’ formatSize(length) β
β β’ formatSpeed(downloadSpeed) β
β β’ formatETA(timeRemaining) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Update Progress Bar β
β (cli-progress library) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Check if progress === 1 β
β Yes β Stop & Exit β
β No β Wait for next event β
βββββββββββββββββββββββββββββββββββββββ
Progress 100% β Stop Progress Bar β Log Success β Exit Process
By default, files are downloaded to ./downloads. To change this:
client.add(magnetURI, { path: './downloads' }, (torrent) => {
// Change './downloads' to your preferred pathCustomize the progress bar display:
export const getDisplayFormat = () => `[{bar}] {percentage}% | Peers: {numPeers} | D: {have} @ {speed} | T: {fullSize} | ETA: {estimate}`;The project requires Node.js 22+. This is enforced in package.json:
"engines": {
"node": ">=22.0.0"
}# Start the application
npm start
# Run tests (not implemented yet)
npm test| Package | Version | Purpose |
|---|---|---|
webtorrent |
^2.1.27 | Core torrent client library |
cli-progress |
^3.12.0 | Terminal progress bar |
cross-env |
^7.0.3 | Cross-platform environment variables |
- New Utility Function: Add to appropriate
src/utils/subdirectory - Client Logic: Modify
src/client/index.js - Entry Point: Update
server.jsfor CLI changes
Solution: Ensure your magnet link starts with magnet:?xt=urn: and contains a valid info hash.
Solution:
- Check your internet connection
- Verify the torrent is still being seeded
- Try a different magnet link
Solution:
- More peers = faster downloads (wait for peer discovery)
- Check your network bandwidth
- Ensure no firewall is blocking connections
Solution:
# Check your Node.js version
node --version
# If < 22.0.0, upgrade Node.js
# Using nvm (recommended):
nvm install 22
nvm use 22To see all Node.js warnings (disabled by default):
# Windows
set NODE_NO_WARNINGS=0 && node server.js
# Linux/macOS
NODE_NO_WARNINGS=0 node server.jsContributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Use ES6+ features
- Follow existing code structure
- Add comments for complex logic
- Update README for new features
This project is licensed under the MIT License.
- WebTorrent: For the amazing torrent library
- cli-progress: For the beautiful progress bars
- Node.js Community: For continuous support
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review existing issues on GitHub
- Create a new issue with detailed information
Made with β€οΈ by danted4
β Star this repo if you find it useful!