svelte-adapter-uws
A SvelteKit adapter powered by uWebSockets.js - the fastest HTTP/WebSocket server for Node.js, written in C++ and exposed through V8.
Most users don’t need to read this page. svelte-realtime handles the adapter for you. This is for power users who want deeper control over WebSocket hooks, plugins, TLS, or deployment.
What you get
- HTTP & HTTPS - native TLS via uWebSockets.js
SSLApp, no reverse proxy needed - WebSocket & WSS - built-in pub/sub with a reactive Svelte client store
- In-memory static file cache - assets loaded once at startup, served from RAM with precompressed brotli/gzip variants
- Backpressure handling - streaming responses that won’t blow up memory
- Graceful shutdown - waits for in-flight requests before exiting
- Health check endpoint -
/healthzout of the box - Zero-config WebSocket - just set
websocket: trueand go
Quick start
Installation
npm install svelte-adapter-uws
npm install uNetworking/uWebSockets.js#v20.60.0 Note: uWebSockets.js is a native C++ addon installed directly from GitHub. Docker requires
node:22-trixie-slimor another glibc >= 2.38 image.
For WebSocket support during development, also install ws:
npm install -D ws HTTP
// svelte.config.js
import adapter from 'svelte-adapter-uws';
export default {
kit: {
adapter: adapter()
}
}; npm run build
node build WebSocket
Three steps: enable the adapter, add the Vite plugin, use the client store.
svelte.config.js
import adapter from 'svelte-adapter-uws';
export default {
kit: {
adapter: adapter({ websocket: true })
}
}; vite.config.js (required for dev mode and production builds)
import { sveltekit } from '@sveltejs/kit/vite';
import uws from 'svelte-adapter-uws/vite';
export default {
plugins: [sveltekit(), uws()]
}; src/routes/+page.svelte
<script>
import { on, status } from 'svelte-adapter-uws/client';
const notifications = on('notifications');
</script>
{#if $status === 'open'}
<span>Connected</span>
{/if}
{#if $notifications}
<p>{$notifications.event}: {JSON.stringify($notifications.data)}</p>
{/if} HTTPS / WSS
No reverse proxy needed. uWebSockets.js handles TLS natively:
npm run build
SSL_CERT=/path/to/cert.pem SSL_KEY=/path/to/key.pem node build The client store automatically uses wss:// when the page is served over HTTPS.
Development, preview & production
| Mode | Command | WebSocket | Notes |
|---|---|---|---|
| Dev | npm run dev | Works | Requires Vite plugin. HMR reloads hooks.ws on save |
| Preview | npm run preview | No | Use node build instead |
| Production | node build | Works | Full uWebSockets.js performance |
Was this page helpful?