Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Client
✓ import { Client } from 'cactus-tunnel'
✗ const Client = require('cactus-tunnel').Client
ESM-only since v0.4.0; CommonJS require will fail.
Server
✓ import { Server } from 'cactus-tunnel'
✗ const { Server } = require('cactus-tunnel')
ESM-only; use dynamic import() if needed in CJS.
createTunnel
✓ import { createTunnel } from 'cactus-tunnel'
Factory function to create tunnel instances.
Demonstrates setting up a cactus-tunnel server and client, forwarding WebSocket to a local TCP server.
import { Server, Client } from 'cactus-tunnel';
import { createServer } from 'net';
// Start server
const server = new Server({ port: 7800 });
await server.listen();
// Start a local TCP server
const localServer = createServer((socket) => {
socket.write('Hello from tunnel!\n');
socket.end();
}).listen(8080);
// Connect client to server and forward to local TCP server
const client = new Client('ws://localhost:7800', 'tcp://localhost:8080');
await client.connect();
// Test connection
const net = await import('net');
const testSocket = net.connect(7800, () => {
testSocket.write('test');
});
testSocket.on('data', (data) => console.log(data.toString()));
process.on('SIGINT', () => {
client.close();
server.close();
localServer.close();
});
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Using CommonJS require() to import cactus-tunnel which is ESM-only since v0.4.0.
fixUse import statement or dynamic import() instead of require().
error:0308010C:digital envelope routines::unsupported
Node.js version mismatch or OpenSSL issues? Possibly running older Node.
Could not connect to server: Connection refused
Tunnel server not running or wrong WebSocket URL.
fixStart server: 'cactus-tunnel server' and verify port 7800 is open.
Audit
Dependencies
No dependency data recorded yet.