TemplatedApp
Routes, listen operations, WebSocket behavior, and pub/sub.
get()post()put()patch()del()options()head()any()ws()publish()numSubscribers()listen()listen_unix()filter()close()@swarmmachina/swm-uws v0.5.1
Node-API 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)
}
})
app.listen(3000, (socket) => {
if (!socket) process.exit(1)
})| 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. |
| Windows ARM64 | Unsupported | There is no current prebuild. |
| 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()any()ws()publish()numSubscribers()listen()listen_unix()filter()close()Request data, snapshots, and streamed responses.
getMethod()getUrl()getHeader()getQuery()getParameter()forEach()snapshot()writeStatus()writeHeader()end()write()tryEnd()onWritable()onData()collectBody()onAborted()Messages, fragments, backpressure, and topics.
send()sendFirstFragment()sendFragment()sendLastFragment()ping()publish()cork()end()close()getBufferedAmount()getRemoteAddress()getUserData()subscribe()unsubscribe()isSubscribed()getTopics()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.
HttpRequest is valid only inside a route or upgrade callback. Call req.snapshot(paramCount) before asynchronous work.
onData and onDataV2 receive a zero-copy ArrayBuffer that is detached after the callback. Copy a chunk if it is needed later.
collectBody(maxSize, callback) returns an application-owned ArrayBuffer, or null when the limit is exceeded.
A Response remains valid after the route callback only when onData, onWritable, collectBody, or onAborted is registered.
Response and WebSocket wrappers are already invalid inside onAborted and close callbacks respectively.
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'