uWebSockets.js Documentation

repository·master·Indexed 27 days ago

https://github.com/unetworking/uwebsockets.js

A high-performance, standards-compliant web server implemented as a native V8 addon for Node.js and serving as the core engine for the Bun runtime. It is written in C++ for extreme scale and low latency, featuring the DeclarativeResponse API for constructing responses via a builder pattern.

Tokens
497
Snippets
1
Records
5
Agent score
44%

What's inside uWebSockets.js

  1. Overview of uWebSockets.js

    master
    uWebSockets.js is a high-performance, standards-compliant web server exposed to Node.js as a native V8 addon. It is written in C++ and is designed for demanding applications, offering significantly higher performance compared to Socket.IO and Fastify. It serves as a core component for the Bun runtime.
  2. Install uWebSockets.js via npm

    master

    uWebSockets.js is not available in the standard NPM registry. To install it, you must use the NPM client to install directly from the GitHub repository. Specify the desired version using the # suffix.

    Note: Ensure you use the correct version tag for your requirements.

    npm install uNetworking/uWebSockets.js#v20.67.0
  3. Troubleshoot Node.js version compatibility errors

    master
    If the module fails to load, it is likely due to an unsupported Node.js version or platform. This version of uWS.js (v20.67.0) only supports Node.js versions 22, 24, and 26 on glibc Linux, macOS, and Windows (Tier 1 platforms).
  4. Use DeclarativeResponse to build responses

    master
    The DeclarativeResponse class provides a builder pattern to construct responses using a sequence of instructions and values. It is used to append headers, body markers, query values, status codes, and data payloads. The final response is generated by calling .end(value), which returns an ArrayBuffer.
  5. DeclarativeResponse API Reference

    master

    Methods available on the DeclarativeResponse class:

    • writeHeader(key, value): Appends a header instruction with 1-byte length values.
    • writeBody(): Appends the body instruction.
    • writeQueryValue(key): Appends a query value instruction with 1-byte length values.
    • writeHeaderValue(key): Appends a header value instruction with 1-byte length values.
    • write(value): Appends a data instruction with a 2-byte length value (max length 65535).
    • writeParameterValue(key): Appends a parameter value instruction with 1-byte length values.
    • writeStatus(status): Appends a status instruction with 1-byte length values.
    • end(value): Appends a final instruction with a 2-byte length value and returns the resulting ArrayBuffer.