WebSockets for Routex.
Install:
yarn add @routex/websocket
# or
npm add @routex/websocket
Setup your app:
const { Routex, TextBody } = require("routex");
const websocket = require("@routex/websocket");
const port = process.env.PORT || 3000;
const app = new Routex();
app.appMiddleware(websocket());
// Must be a GET request.
app.get(
"/",
websocket.socketHandler((socket) => {
// Echo server
socket.on("message", (data) => {
socket.send("You said: " + data);
});
})
);
app.listen(port).then(() => console.log(`Listening on ${port}`));
We support all currently active and maintained Node LTS versions, include current Node versions.
Please file feature requests and bugs at the issue tracker.