Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/3rd-party-lib/websocket-with-ws
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Websocket with ws library

https://github.com/websockets/ws

### Import

```ts
// Node or Bun
import { WebSocketServer } from 'ws'

```

### Usage

```ts
// Node or Bun
const app = nhttp();

const server = createServer(app.handle as any);

const wss = new WebSocketServer({ server });

wss.on("connection", function connection(ws) {
console.log('ws -> client connected');

ws.on("error", function error(error) {
console.error('error', error)
});

ws.on("message", function message(message) {
console.log("received: %s", message);
});

ws.send("something");
});
```