Hedystia 2.3 Delivers Native Node.js Support and Universal WebSockets
These articles are AI-generated summaries. Please check the original sources for full details.
Hedystia 2.3: Universal WebSocket, Native Node.js, PostgreSQL, and 20+ New Validations
Hedystia 2.3 transitions its HTTP layer to run natively on Node.js, removing the previous requirement for specialized adapters. The release introduces a universal WebSocket package that functions identically across Bun, Node.js, and Deno runtimes.
Why This Matters
The shift toward native runtime support addresses the friction of environment-specific adapters which often introduce maintenance overhead and performance bottlenecks. By unifying the WebSocket and HTTP interfaces across disparate engines like Deno and Node.js, developers can maintain a single codebase without sacrificing environment-specific optimizations or stability.
Key Insights
- Native Node.js support allows the HTTP layer to use listen(port) directly, matching Bun’s implementation patterns.
- @hedystia/ws enables topic-based pub/sub and portable server logic across Bun, Node.js, and Deno.
- The @hedystia/db package now includes a native PostgreSQL driver via the pg package, supporting full CRUD and transactions.
- Over 20 new schema validation factories were added, including h.discriminatedUnion(), h.lazy(), and h.pipe().
- @hedystia/astro integration facilitates reactive UI components without a virtual DOM using signals and SSR.
Working Examples
Native Node.js server initialization without adapters
import Framework from "hedystia";
new Framework().get("/", () => "ok").listen(3000);
Universal WebSocket server and client imports
import { WebSocketServer } from "@hedystia/ws/server";
import { createWebSocket } from "@hedystia/ws/client";
PostgreSQL driver configuration for @hedystia/db
const db = database({
schemas: { users },
database: { name: "postgres", provider: "pg" },
connection: { host: "localhost", user: "postgres", database: "mydb" },
});
Practical Applications
- Cross-runtime Deployment: Deploying the same application logic to Bun or Node.js environments without modifying the transport layer.
- Pitfall: Manual adapter configuration in legacy setups leading to inconsistent request handling across different cloud providers.
- Auth Integration: Utilizing @hedystia/db as the backend for Better Auth to manage type-safe user sessions.
- Pitfall: Inefficient data validation in complex schemas by failing to use the new .strict() and .refine() methods.
References:
Continue reading
Next article
Solving Repository Setup Drift with Ota CLI
Related Content
Solving WebSocket Authentication: Why Cookies Beat Bearer Tokens
Learn why the native browser WebSocket API's lack of custom header support makes HTTP-only cookies the superior choice for secure authentication.
Node.js vs. FastAPI: Architecting High-Concurrency APIs with libuv and asyncio
Node.js and FastAPI both handle high-concurrency but utilize different execution models, from single-threaded libuv loops to multi-process asyncio workers.
Production Node.js Caching: Implementing Redis, LRU, and CDN Edge Layers
Optimize Node.js production systems by reducing database load by 80% and cutting p99 latency through a multi-layer caching strategy involving Redis, LRU, and CDN edge.