Overview
The P2P file sharing application is started using thepeer.js entry point with command-line arguments.
Basic Syntax
Required Parameters
The TCP port number on which this node will listen for incoming connections.Validation: Must be a valid integer between 1 and 65535.Example:The port is parsed as an integer in
src/peer.js:19:The file path for this node.The file path is read in
- For seeds: Path to an existing file to share
- For leechers: Path where the downloaded file will be saved
src/peer.js:22:Optional Parameters
Initial peer to connect to in the format The peer address is parsed in
host:port. This is used by leechers to connect to their first seed or peer.Format: <host>:<port> where:hostcan be an IP address (e.g.,192.168.1.100) or hostname (e.g.,localhost,127.0.0.1)portmust be a valid port number
src/peer.js:39-50:For leechers without an initial peer, the node will print a warning:
Validation Rules
Required Arguments
Both--port and --file are required. If either is missing, the program displays usage information and exits:
Invalid Arguments
If any unrecognized argument is provided, the program exits with usage information:Peer Format Validation
The--peer parameter must follow the host:port format:
- Must contain a colon (
:) separator - Port must be a valid integer
- If validation fails, the program exits with an error message
Usage Examples
Starting a Seed Node
Starting a Leecher Node
Using npm Scripts
Thepackage.json defines convenient npm scripts:
package.json:6-10:
Help and Usage Information
To display usage information, run the command without required arguments:src/peer.js:4-9: