TemplatedApp
Routes, listen operations, WebSocket behavior, and pub/sub.
get()post()put()patch()del()options()head()connect()trace()any()ws()publish()numSubscribers()listen()listen_unix()filter()getHttpTransportStats()close()@swarmmachina/swm-uws v0.7.3
Native V8 binding
A native V8 binding compatible with the regular non-TLS uWebSockets.js HTTP/WebSocket surface. The uWebSockets.js 20.69.0 sources are pinned and vendored in the repository.
Choose swm-uws for direct App() API access, migration of an existing uWebSockets.js application, or when the higher-level swm-core abstractions are unnecessary.
npm install @swarmmachina/swm-uwsimport uWS from '@swarmmachina/swm-uws'
const app = uWS.App()
app.get('/', (res) => {
res.writeHeader('content-type', 'application/json')
.end('{"ok":true}')
})
app.ws('/ws', {
message(ws, message, isBinary) {
ws.send(message, isBinary)
}
})
let listenSocket
app.listen(3000, (socket) => {
if (!socket) process.exit(1)
listenSocket = socket
})
process.on('SIGTERM', () => {
if (listenSocket) uWS.us_listen_socket_close(listenSocket)
app.close()
})| Environment | Status | Note |
|---|---|---|
| Node.js 22 / 24 | Supported | Prebuilds are released for supported ABIs. |
| Linux x64 + glibc | Supported | Portable generic x86-64 build. |
| Windows x64 | Supported | A native build is included in the package. |
| macOS arm64 / x64 | Supported | Apple Silicon and Intel are supported. |
| Linux ARM64 / Windows ARM64 | Unsupported | There are no current prebuilds. |
| Alpine / musl | Unsupported | A glibc environment is required. |
| TLS / permessage-deflate | Disabled | Terminate TLS in front of the application. |
Routes, listen operations, WebSocket behavior, and pub/sub.
get()post()put()patch()del()options()head()connect()trace()any()ws()publish()numSubscribers()listen()listen_unix()filter()getHttpTransportStats()close()Owned request values, selective header prefetch, and streamed responses.
getMethod()getCaseSensitiveMethod()getUrl()getHeader()getQuery()getParameter()forEach()prefetch(plan)writeStatus()writeHeader()end()write()tryEnd()onWritable()onData()onDataV2()collectBody()pause()resume()onAborted()Messages, fragments, backpressure, and topics.
send()sendFirstFragment()sendFragment()sendLastFragment()ping()publish()cork()end()close()getBufferedAmount()getRemoteAddress()getUserData()subscribe()unsubscribe()isSubscribed()getTopics()JavaScript callback typing, binding metadata, and listener control.
defineHttpHandler()defineWebSocketBehavior()RequestPrefetchPlanversion()capabilities()us_listen_socket_close()Complete signatures, types, and examples are available in the source repository README and TypeScript declarations.
The binding stays close to native uWS, so wrapper and buffer lifetimes are part of the API contract.
The wrapper is valid only inside a route or upgrade callback. Individual get* methods return owned JavaScript strings; for selected headers with duplicate and missing-value semantics, call req.prefetch() with a precompiled RequestPrefetchPlan.
App({ http }) accepts header limits, phase-specific timeouts, and a minimum body rate. getHttpTransportStats() exposes activeConnections and rejection counters without scanning connections.
onData and onDataV2 receive a zero-copy ArrayBuffer that is detached after the callback. Copy a chunk if it is needed later.
res.pause() stops further socket reads, although callbacks can still receive chunks already present in the current parser buffer. Call res.resume() only when the consumer is ready for more input; otherwise the upload remains under backpressure.
collectBody(maxSize, callback) accepts a 0..1 GiB byte limit and returns an application-owned ArrayBuffer, or null when exceeded. A global memory limit remains the application’s responsibility.
A Response remains valid after the route callback only when onData, onDataV2, onWritable, collectBody, or onAborted is registered.
Response and WebSocket wrappers are already invalid inside onAborted and close callbacks respectively.
Response methods set Content-Length and Transfer-Encoding. Writing either header manually is rejected to prevent ambiguous HTTP framing.
A callback exception reaches Node.js as the original error; the current request or socket sequence stops and the affected wrapper is invalidated.
Concise answers about package selection, runtime contracts, and production constraints.
swm-uws is an experimental non-TLS V8 binding for Node.js 22 and 24 that is compatible with the regular uWebSockets.js App() surface. Release 0.7.3 pins uWebSockets.js 20.69.0, ships platform-specific prebuilds, and has no runtime npm dependencies.
Yes, for the documented non-TLS App() surface you can install the uwebsockets.js@npm:@swarmmachina/swm-uws alias. SSLApp, H3App, compression, SNI, and experimental upstream APIs are unsupported and require an explicit migration.
HttpRequest itself expires after the route or upgrade callback, but strings returned by getMethod(), getUrl(), getQuery(), getHeader(), and getParameter() are JavaScript-owned and may be retained. For selected headers with duplicate and missing-value semantics, compile a RequestPrefetchPlan and call req.prefetch(plan) inside the callback.
Pass App({ http: { ... } }) with maxHeaderSize, maxHeaderCount, headersTimeoutMs, keepAliveTimeoutMs, bodyIdleTimeoutMs, minBodyRateBytesPerSec, and responseWriteTimeoutMs. Read rejection counters and activeConnections through app.getHttpTransportStats().
onData and onDataV2 expose a zero-copy ArrayBuffer that is detached after the callback. collectBody(maxSize, callback) returns an application-owned ArrayBuffer or null above a limit of up to 1 GiB; aggregate memory budgeting and admission control remain application responsibilities.
res.pause() stops further socket reads when the consumer is temporarily unable to accept input. A callback can still receive chunks already in the current parser buffer. Call res.resume() only after downstream capacity is available: an omitted resume is no longer masked by continued reads and leaves the upload under backpressure.
It supports Node.js 22/24, Linux x64 with glibc, Windows x64, and macOS arm64/x64. TLS/SSLApp, H3App, permessage-deflate, SNI, Alpine/musl, Linux ARM64, and Windows ARM64 are unsupported; terminate TLS before the application.
If an application uses the supported regular App() surface, install the package under the original name. SSLApp, H3App, compression, SNI, and experimental APIs require an explicit migration.
npm install uwebsockets.js@npm:@swarmmachina/swm-uws// The original import stays unchanged
import uWS from 'uwebsockets.js'