Skip to main content

Documentation Index

Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

WebSocket endpoints work through ngrok’s HTTP endpoints without any changes. However, there is currently no support for introspecting WebSockets beyond the initial 101 Switching Protocols response. If you want to use WebSockets with HTTP, you only need one ngrok endpoint: you can start a server where listeners for both protocols share a single port.

What you’ll need

1. Install dependencies

npm install ws

2. Create the server

Create a server.js file:
import { createServer } from 'http';
import { WebSocketServer } from 'ws';

const server = createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('OK\n');
});

const wss = new WebSocketServer({ server });

wss.on('connection', (ws) => {
  ws.on('message', (data) => ws.send(`Echo: ${data}`));
  ws.send('Hello from WebSocket');
});

server.listen(8000);

3. Start ngrok

A single ngrok endpoint handles traffic for both protocols.
ngrok http 8000
Connect to your WebSocket using the wss:// scheme:
const ws = new WebSocket('wss://<your-ngrok-domain>');