@h0rn0chse/socket-server
v1.2.0
Published
Extends express.js and ws server with some utilities
Downloads
10
Maintainers
Readme
socket-server
Extends express.js and ws server with some utilities
Getting Started
This project is available as npm package.
Installation
npm i @h0rn0chse/socket-server
Basic Usage
import { registerSocketHandler, registerXhrHandler, send, startServer } from "@h0rn0chse/socket-server";
startServer({
host: "localhost",
port: 3000
})
registerXhrHandler("get", "/data/blob", (req, res, token) => {
res.json({ foo: "bar" })
res.end();
});
registerSocketHandler("ping", (ws, data, uuid) => {
send(ws, "pong", { foo: "bar" });
});
For more examples see the documentation and the demo files:
- Basic Usage: test.js
- Client Handler: test_handler.js
- Custom Adapter: test_custom.js
Limitations
This module can only be used with esm modules.
// package.json
{
"type": "module"
}
Libraries
- WebSockets github.com/websockets/ws
- Request Handling github.com/expressjs/express