Skip to content

danted4/nodeWT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌊 nodeWT - WebTorrent CLI Client

 β–ˆβ–ˆβ–ˆβ–„    β–ˆ  β–’β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–“β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–„ β–“β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆ     β–ˆβ–‘β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–“
 β–ˆβ–ˆ β–€β–ˆ   β–ˆ β–’β–ˆβ–ˆβ–’  β–ˆβ–ˆβ–’β–’β–ˆβ–ˆβ–€ β–ˆβ–ˆβ–Œβ–“β–ˆ   β–€ β–“β–ˆβ–‘ β–ˆ β–‘β–ˆβ–‘β–“  β–ˆβ–ˆβ–’ β–“β–’
β–“β–ˆβ–ˆ  β–€β–ˆ β–ˆβ–ˆβ–’β–’β–ˆβ–ˆβ–‘  β–ˆβ–ˆβ–’β–‘β–ˆβ–ˆ   β–ˆβ–Œβ–’β–ˆβ–ˆβ–ˆ   β–’β–ˆβ–‘ β–ˆ β–‘β–ˆ β–’ β–“β–ˆβ–ˆβ–‘ β–’β–‘
β–“β–ˆβ–ˆβ–’  β–β–Œβ–ˆβ–ˆβ–’β–’β–ˆβ–ˆ   β–ˆβ–ˆβ–‘β–‘β–“β–ˆβ–„   β–Œβ–’β–“β–ˆ  β–„ β–‘β–ˆβ–‘ β–ˆ β–‘β–ˆ β–‘ β–“β–ˆβ–ˆβ–“ β–‘
β–’β–ˆβ–ˆβ–‘   β–“β–ˆβ–ˆβ–‘β–‘ β–ˆβ–ˆβ–ˆβ–ˆβ–“β–’β–‘β–‘β–’β–ˆβ–ˆβ–ˆβ–ˆβ–“ β–‘β–’β–ˆβ–ˆβ–ˆβ–ˆβ–’β–‘β–‘β–ˆβ–ˆβ–’β–ˆβ–ˆβ–“   β–’β–ˆβ–ˆβ–’ β–‘
β–‘ β–’β–‘   β–’ β–’ β–‘ β–’β–‘β–’β–‘β–’β–‘  β–’β–’β–“  β–’ β–‘β–‘ β–’β–‘ β–‘β–‘ β–“β–‘β–’ β–’    β–’ β–‘β–‘
β–‘ β–‘β–‘   β–‘ β–’β–‘  β–‘ β–’ β–’β–‘  β–‘ β–’  β–’  β–‘ β–‘  β–‘  β–’ β–‘ β–‘      β–‘
   β–‘   β–‘ β–‘ β–‘ β–‘ β–‘ β–’   β–‘ β–‘  β–‘    β–‘     β–‘   β–‘    β–‘
         β–‘     β–‘ β–‘     β–‘       β–‘  β–‘    β–‘

A powerful, feature-rich Node.js CLI wrapper for WebTorrent with real-time progress tracking, peer statistics, and beautiful terminal UI.

Node.js Version License WebTorrent


πŸ“‹ Table of Contents


✨ Features

  • πŸš€ 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

πŸ—οΈ Architecture

High-Level Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         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                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  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
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

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 Responsibilities

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()

πŸš€ Installation

Prerequisites

  • Node.js: Version 22.0.0 or higher (LTS recommended)
  • npm: Comes with Node.js
  • Operating System: Windows, macOS, or Linux

Quick Start

  1. Clone or Download the Repository

    git clone <repository-url>
    cd nodeWT
  2. Install Dependencies

    npm install
  3. Verify Installation

    node --version  # Should show v22.x.x

πŸ’» Usage

Basic Usage

  1. Start the Application

    npm start
  2. Enter Magnet URL

    Please paste your magnetURI:
    
    magnet:?xt=urn:btih:...
    
  3. Monitor Progress

    [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘] 75% | Peers: 12 | D: 750.45 MB @ 2.5 MB/s | T: 1.0 GB | ETA: 2 minutes
    

Example Session

$ 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 !

Progress Bar Legend

[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘] 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

πŸ”§ How It Works

1. Initialization Phase

User Input β†’ Validation β†’ Spinner Animation β†’ WebTorrent Client Init

2. Connection Phase

Magnet URI β†’ DHT Lookup β†’ Peer Discovery β†’ Establish Connections

3. Download Phase

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  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          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

4. Completion Phase

Progress 100% β†’ Stop Progress Bar β†’ Log Success β†’ Exit Process

βš™οΈ Configuration

Download Location

By default, files are downloaded to ./downloads. To change this:

client.add(magnetURI, { path: './downloads' }, (torrent) => {
    // Change './downloads' to your preferred path

Progress Bar Format

Customize the progress bar display:

export const getDisplayFormat = () => `[{bar}] {percentage}% | Peers: {numPeers} | D: {have} @ {speed} | T: {fullSize} | ETA: {estimate}`;

Node.js Version

The project requires Node.js 22+. This is enforced in package.json:

"engines": {
  "node": ">=22.0.0"
}

πŸ› οΈ Development

Available Scripts

# Start the application
npm start

# Run tests (not implemented yet)
npm test

Dependencies

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

Adding New Features

  1. New Utility Function: Add to appropriate src/utils/ subdirectory
  2. Client Logic: Modify src/client/index.js
  3. Entry Point: Update server.js for CLI changes

πŸ› Troubleshooting

Common Issues

Issue: "Invalid magnet URL"

Solution: Ensure your magnet link starts with magnet:?xt=urn: and contains a valid info hash.

Issue: No peers found

Solution:

  • Check your internet connection
  • Verify the torrent is still being seeded
  • Try a different magnet link

Issue: Slow download speeds

Solution:

  • More peers = faster downloads (wait for peer discovery)
  • Check your network bandwidth
  • Ensure no firewall is blocking connections

Issue: Node version error

Solution:

# Check your Node.js version
node --version

# If < 22.0.0, upgrade Node.js
# Using nvm (recommended):
nvm install 22
nvm use 22

Debug Mode

To 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.js

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Code Style

  • Use ES6+ features
  • Follow existing code structure
  • Add comments for complex logic
  • Update README for new features

πŸ“„ License

This project is licensed under the MIT License.


πŸ™ Acknowledgments

  • WebTorrent: For the amazing torrent library
  • cli-progress: For the beautiful progress bars
  • Node.js Community: For continuous support

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Review existing issues on GitHub
  3. Create a new issue with detailed information

Made with ❀️ by danted4

⭐ Star this repo if you find it useful!

About

Node Client wrapper on webtorrent.

Resources

Stars

Watchers

Forks

Packages

No packages published