@antash-mishra/tunnel-client v1.0.0
WebSocket Tunnel Client
A simple, command-line WebSocket-based tunnel client that allows you to expose your local server to the internet through a tunnel server.
This tool connects to a compatible WebSocket tunnel server (like the one in the parent directory of this project) and forwards incoming public requests to a specified local server.
Features
- Expose any local HTTP/HTTPS server to a public URL.
 - Connects via secure (WSS) or insecure (WS) WebSockets.
 - Simple command-line interface.
 - Automatic reconnection attempts on disconnect.
 - Configurable tunnel server URL.
 
Installation
Install the client globally using npm:
# Option 1: Install directly from the source code (for development)
cd client # Navigate to this directory
npm install -g .
# Option 2: Install from NPM (if published)
# npm install -g websocket-tunnel-clientThis installation makes the tunnel-client command available system-wide in your terminal.
Usage
The basic command structure is:
tunnel-client <local-server-url> [options]Arguments:
<local-server-url>: Required. The full URL of your local server that you want to expose. Include the protocol (httporhttps).- Example: 
http://localhost:3000 - Example: 
https://127.0.0.1:8443 
- Example: 
 
Options:
-s, --server-url <url>: The WebSocket URL (ws://orwss://) of the tunnel server to connect to.- Defaults to 
ws://localhost:8080(useful if running the server locally). - For a deployed server (e.g., on Fly.io), use its public WebSocket address like 
wss://your-app-name.fly.dev. 
- Defaults to 
 -h, --help: Display help information and exit.
Examples:
Expose local server
http://localhost:5000using the default tunnel server (ws://localhost:8080):tunnel-client http://localhost:5000Expose local server
http://127.0.0.1:8080using a specific, deployed tunnel server:tunnel-client http://127.0.0.1:8080 -s wss://my-tunnel-app.fly.devExpose a local HTTPS server:
tunnel-client https://localhost:8443
Upon successful connection, the client will print the assigned public URL.
How It Works
- The 
tunnel-clientCLI connects to the specified--server-urlvia WebSocket. - The tunnel server accepts the connection and assigns a unique Tunnel ID.
 - The client prints the public URL constructed from the server URL and the Tunnel ID (e.g., 
https://my-tunnel-app.fly.dev/<tunnel-id>). - When an HTTP request hits the public URL:
- The tunnel server forwards the request details (method, path, headers, body) to the connected client over the WebSocket.
 - The 
tunnel-clientreceives the details and makes an equivalent HTTP/HTTPS request to your<local-server-url>. - The response from your local server (status, headers, body) is captured by the 
tunnel-client. - The client sends the response details back to the tunnel server over the WebSocket.
 - The tunnel server sends the HTTP response back to the original requester.
 
 
Development (Contributing)
- Clone the main project repository.
 - Navigate to the client directory: 
cd client - Install development dependencies: 
npm install - Make your code changes in 
tunnel-client.js. - You can run the client directly during development without global installation:
node tunnel-client.js http://localhost:3000 --server-url ws://localhost:8080 
License
Running as a Service (Optional)
For persistent operation after global installation, you can use a process manager like PM2:
pm2 start $(which tunnel-client) --name "my-tunnel" -- <local-server-url> [options]
# Example:
pm2 start $(which tunnel-client) --name "api-tunnel" -- http://localhost:3001 -s wss://my-tunnel-server.com7 months ago