@h0rn0chse/socket-server

1.2.0 • Public • Published

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:

Limitations

This module can only be used with esm modules.

// package.json
{
    "type": "module"
}

Libraries

Package Sidebar

Install

npm i @h0rn0chse/socket-server

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

43.5 kB

Total Files

24

Last publish

Collaborators

  • h0rn0chse