2024-05-09 20:51:25 +08:00
|
|
|
# WebSocket helper for Node.js
|
|
|
|
|
2025-03-19 16:53:11 +08:00
|
|
|
[](https://codecov.io/github/honojs/middleware)
|
|
|
|
|
2024-05-09 20:51:25 +08:00
|
|
|
A WebSocket helper for Node.js
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import { createNodeWebSocket } from '@hono/node-ws'
|
|
|
|
import { Hono } from 'hono'
|
|
|
|
import { serve } from '@hono/node-server'
|
|
|
|
|
|
|
|
const app = new Hono()
|
|
|
|
|
|
|
|
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app })
|
|
|
|
|
2025-03-19 16:53:11 +08:00
|
|
|
app.get(
|
|
|
|
'/ws',
|
|
|
|
upgradeWebSocket((c) => ({
|
|
|
|
// https://hono.dev/helpers/websocket
|
|
|
|
}))
|
|
|
|
)
|
2024-05-09 20:51:25 +08:00
|
|
|
|
|
|
|
const server = serve(app)
|
|
|
|
injectWebSocket(server)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Author
|
|
|
|
|
|
|
|
Shotaro Nakamura <https://github.com/nakasyou>
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
2025-03-19 16:53:11 +08:00
|
|
|
MIT
|