diff --git a/docs/3rd-party-lib/websocket-with-ws b/docs/3rd-party-lib/websocket-with-ws new file mode 100644 index 0000000..ef4036d --- /dev/null +++ b/docs/3rd-party-lib/websocket-with-ws @@ -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"); +}); +```