Server SDKs
TypeScript SDK
Server-side Hypen with TypeScript, Bun, and Node.js
TypeScript SDK
The TypeScript SDK is the primary way to run Hypen servers.
Installation
bun add @hypen-space/core
# or
npm install @hypen-space/coreQuick Start
import { serve, app } from "@hypen-space/core";
const module = app
.defineState({ message: "Hello!" })
.onAction("update", async ({ action, state }) => {
state.message = action.payload.text;
});
const ui = `
Column {
Text("\${state.message}")
.fontSize(24)
}
`;
serve({ module, ui, port: 3000 });RemoteServer API
For more control:
import { RemoteServer, app } from "@hypen-space/core";
const module = app
.defineState({ count: 0 })
.onAction("increment", async ({ state }) => {
state.count++;
})
.build();
new RemoteServer()
.module("Counter", module)
.ui(ui)
.onConnection((client) => {
console.log(`Connected: ${client.id}`);
})
.onDisconnection((client) => {
console.log(`Disconnected: ${client.id}`);
})
.listen(3000);Configuration
new RemoteServer()
.config({
port: 3000,
hostname: "0.0.0.0"
})
.listen();Authentication
Add auth before WebSocket upgrade:
Bun.serve({
port: 3000,
fetch(req, server) {
const token = req.headers.get("Authorization");
if (!validateToken(token)) {
return new Response("Unauthorized", { status: 401 });
}
server.upgrade(req);
},
websocket: {
// RemoteServer handlers
}
});Deployment
Deploy to any platform supporting WebSockets:
- Fly.io
- Railway
- Render
- AWS/GCP/Azure
- Your own VPS