Server Setup & Configuration
Set up a Mesh server with just a few lines of code.
Basic usage
import { } from "@mesh-kit/server";
const = new ({
: 8080,
: { : "localhost", : 6379 },
});
.("echo", async () => {
return `echo: ${.}`;
});
The server starts listening immediately. To be sure it’s up, you can: await server.ready()
.
Configuration options
const = new ({
: 8080,
: "0.0.0.0", // default
: "/mesh", // WebSocket path (default "/")
: {
: "localhost",
: 6379,
: "optional",
},
: 30_000,
: 5_000,
: 1,
: true,
});
redisOptions
are passed directly to ioredis . You can use any valid ioredis client option here.
Handling connections
.(async () => {
.("Connected:", .);
await ..(, {
: .(),
});
});
.(async () => {
.("Disconnected:", .);
});
Graceful shutdown
.("SIGINT", async () => {
.("Shutting down...");
await .();
.(0);
});
Using with Express
To integrate with an existing Express + HTTP server:
import from "express";
import { } from "@mesh-kit/server";
const = ();
const = .listen(3000, () => {});
const = new ({
,
// configure as usual
});
Next steps
Last updated on