@qiudaomao/node-frp
v1.1.5
Published
A Node.js implementation of Fast Reverse Proxy (FRP) for TCP port forwarding
Downloads
265
Maintainers
Readme
Node FRP
A Node.js implementation of Fast Reverse Proxy (FRP) for TCP port forwarding with web-based administration.
Features
- TCP port forwarding - Forward local services through the server to the internet
- Client/Server architecture - Centralized server with multiple client support
- Database-backed configuration - SQLite database for persistent storage
- Token-based authentication - Secure client authentication with auto-generated tokens
- Web UI Administration - Full-featured web interface for managing clients and port forwards
- Real-time status monitoring - Live connection status tracking
- Dynamic configuration updates - Changes take effect immediately without restart
- Heartbeat mechanism - Automatic detection and cleanup of dead connections
- Enable/disable toggles - Quick control over port forwards without editing
- REST API - Programmatic access to all management functions
Installation
npm install -g @qiudaomao/node-frpConfiguration
Server Configuration (frps.yaml)
bindPort: 7000
databasePath: ./frp.db
trafficFlushInterval: 30 # Traffic flush interval in seconds (default: 30)
webUI:
enabled: true
port: 8080
username: admin
password: adminConfiguration Options:
bindPort- Control port for client connections (default: 7000)databasePath- Path to SQLite database file (default: ./frp.db)trafficFlushInterval- How often to flush traffic statistics to database in seconds (default: 30)webUI.enabled- Enable/disable web UI (default: true)webUI.port- Web UI port (default: 8080)webUI.username- Web UI admin username (default: admin)webUI.password- Web UI admin password (default: admin)
Client Configuration (frpc.yaml)
serverAddr: "your.server.ip"
serverPort: 7000
token: "your-client-token"Note: Port forward configuration is now managed through the web UI and is no longer required in the client config.
Usage
Start Server
node-frp server
node-frp server <frps.yaml>
# run from source
node src/cli.js server
# or with custom config
node src/cli.js server custom-server.yamlThe server will automatically start the web UI at http://localhost:8080 (if enabled).
Start Client
node-frp client
node-frp client <frpc.yaml>
# run from source
node src/cli.js client
# or with custom config
node src/cli.js client custom-client.yamlWeb UI Administration
The web interface provides complete management capabilities:
- Dashboard - Overview with real-time status and statistics
- Client Management - Create, view, edit, enable/disable, and delete clients
- Port Forward Management - Create, view, edit, enable/disable, and delete port forwards
- Live Status Updates - See which clients are connected and which forwards are actively forwarding traffic
Accessing the Web UI
- Start the server with web UI enabled (default)
- Open http://localhost:8080 in your browser
- Login with the default credentials:
- Username:
admin - Password:
admin
- Username:
- Important: Change the default username and password in the server configuration or environment variables
Managing Clients
Create a Client:
- Navigate to "Clients" → "Add Client"
- Enter name and description
- Copy the generated authentication token
Configure Client:
- Add the token to the client's
frpc.yamlfile - Set
serverAddrandserverPortto point to your server
- Add the token to the client's
Monitor Status:
- Connected: Client is actively connected to the server
- Offline: Client is not connected
Managing Port Forwards
Create Port Forward:
- Navigate to "Port Forwards" → "Add Port Forward"
- Select client and configure ports
- Remote port: External port on server
- Local IP/Port: Target service on client machine
Status Indicators:
- Active (green): Port forward is enabled and client is connected
- Client Offline (yellow): Port forward is enabled but client is disconnected
- Disabled (yellow): Port forward is manually disabled
Traffic Monitoring:
- Each port forward displays total traffic (bytes transferred)
- Traffic updates in real-time (flushed every 30 seconds by default)
- Hover over traffic numbers to see in/out breakdown
- Last activity timestamp shows when port forward was last used
- Traffic persists across server restarts (stored in database)
Quick Actions:
- Enable/Disable toggles without editing
- Delete operations with confirmation
- All changes take effect immediately for connected clients
How It Works
Server Setup:
- Server starts and initializes SQLite database
- Web UI starts (if enabled) for administration
- Server listens on control port (default 7000)
Client Connection:
- Client connects to server's control port
- Client authenticates using token
- Server retrieves port forward assignments from database
- Server sends configuration to client
Port Forward Activation:
- Server automatically creates proxy listeners for enabled port forwards
- Only active when client is connected
- Heartbeat mechanism monitors connection health
Traffic Flow:
- External user connects to server's remote port
- Server notifies client of new connection
- Client establishes data connection to server
- Client connects to local service
- Data flows: External Client ↔ Server ↔ FRP Client ↔ Local Service
Dynamic Updates:
- Changes made via web UI take effect immediately
- Connected clients receive configuration updates in real-time
- Proxy servers are created/destroyed automatically
Example Workflow
Setup Server
1. Start the server:
node src/cli.js server2. Access Web UI:
- Open http://localhost:8080
- Login with username:
admin, password:admin
3. Create a client:
- Navigate to "Clients" → "Add Client"
- Name:
my-home-server - Copy the generated token
4. Create port forwards:
- Navigate to "Port Forwards" → "Add Port Forward"
- SSH Forward:
- Client:
my-home-server - Name:
ssh - Remote Port:
6000 - Local IP:
127.0.0.1 - Local Port:
22
- Client:
Setup Client
1. Configure client (frpc.yaml):
serverAddr: "your.server.ip"
serverPort: 7000
token: "paste-token-from-web-ui"2. Start the client:
node src/cli.js client3. Verify in Web UI:
- Dashboard should show client as "Connected"
- Port forward should show status as "Active" (green)
Access Your Service
Connect to SSH through the tunnel:
ssh [email protected] -p 6000Traffic Monitoring
The FRP server provides real-time traffic monitoring for all port forwards:
Features
- Real-time tracking: Traffic is counted as data flows through connections
- Periodic updates: Statistics are flushed to database every 30 seconds (configurable)
- Persistent storage: Traffic data survives server restarts
- Web UI display:
- Dashboard shows total traffic across all port forwards
- Port forwards page shows traffic per forward with last activity timestamp
- Tooltip displays in/out breakdown on hover
How It Works
- In-memory counters: As data flows, bytes are tracked in memory for minimal overhead
- Periodic flush: Every N seconds (default 30), accumulated traffic is written to database
- Combined view: Web UI displays database traffic + current in-memory traffic for real-time updates
- Graceful shutdown: Remaining traffic is flushed when server stops
Configuration
Adjust the flush interval in your server config:
trafficFlushInterval: 30 # Flush every 30 secondsShorter intervals = more frequent database writes but more accurate real-time data Longer intervals = less database I/O but less frequent updates
REST API
The server provides a REST API for programmatic access (requires authentication):
Clients
GET /api/clients- List all clientsPOST /api/clients- Create clientGET /api/clients/:id- Get client detailsPUT /api/clients/:id- Update clientDELETE /api/clients/:id- Delete client
Port Forwards
GET /api/port-forwards- List all port forwards with connection status and trafficPOST /api/port-forwards- Create port forwardGET /api/port-forwards/:id- Get port forward detailsGET /api/port-forwards/:id/traffic- Get traffic statistics for specific port forward (supports?since=date)PUT /api/port-forwards/:id- Update port forwardPUT /api/port-forwards/:id/toggle- Enable/disable port forwardDELETE /api/port-forwards/:id- Delete port forward
Statistics
GET /api/statistics- Get system statistics
Environment Variables
You can override configuration using environment variables:
WEB_PORT- Web UI port (default: 8080)DB_PATH- Database file path (default: ./frp.db)ADMIN_USERNAME- Web UI admin username (default: 'admin')ADMIN_PASSWORD- Web UI admin password (default: 'admin')TRAFFIC_FLUSH_INTERVAL- Traffic flush interval in seconds (default: 30)
Architecture
┌─────────────────┐
│ Web Browser │
│ (Port 8080) │
└────────┬────────┘
│ HTTP/REST
↓
┌─────────────────┐
│ FRP Server │
│ - Control Port │◄────────┐
│ - Web UI │ │ Control Connection
│ - Database │ │ (Authentication & Config)
│ - Proxy Ports │ │
└────────┬────────┘ │
│ │
│ Proxy Traffic │
↓ │
┌─────────────────┐ ┌────────────────┐
│ External Client │ │ FRP Client │
│ │ │ - Heartbeat │
└─────────────────┘ │ - Local Conns │
└───────┬────────┘
│
↓
┌───────────────┐
│ Local Service │
│ (SSH, HTTP, │
│ etc.) │
└───────────────┘Security Considerations
- Change default credentials: Update
usernameandpasswordin server config or use environment variables - Use strong passwords: Choose complex passwords for production environments
- Use strong tokens: Tokens are auto-generated with crypto.randomBytes
- HTTPS: Consider placing Web UI behind reverse proxy with SSL
- Firewall: Only expose necessary ports (control port and proxy ports)
- Session management: Sessions expire after 24 hours of inactivity
Troubleshooting
Client won't connect
- Verify server IP and port in client config
- Check token is correct
- Ensure firewall allows connection to control port
Port forward shows "Client Offline"
- Check client is running and connected
- Verify in Dashboard that client shows "Connected"
- Review server/client logs for errors
Port forward disabled unexpectedly
- Someone may have toggled it via Web UI
- Check if client was deleted (cascades to port forwards)
"Port already in use" error
- Another process is using the port
- Check for orphaned processes:
netstat -tulpn | grep <port> - Restart the server to clean up connections
License
MIT
