Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

fastify-uws

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-uws

A performant HTTP and WebSocket server for Fastify with uWebSockets.

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
200
181.69%
Maintainers
1
Weekly downloads
 
Created
Source

fastify-uws

fastify-uws

A performant HTTP and WebSocket server for Fastify with uWebSockets.

Installation

Install fastify-uws with your favorite package manager:

$ npm i fastify-uws
# or
$ yarn add fastify-uws
# or
$ pnpm i fastify-uws
# or
$ bun add fastify-uws

Supported

fastify-uws v2.x supports the following versions:

  • Node.js: v20, v22, and v24
  • fastify: v5.x
  • @fastify/websocket: v11.x

Breaking Changes from v1.x

While fastify-uws v1.x supports the same Node.js, fastify, and @fastify/websocket versions as v2.x, the eventsource API has been removed in v2.x as Fastify now provides official Server-Sent Events (SSE) support via @fastify/sse.

- import { eventsource } from 'fastify-uws';
+ import sse from '@fastify/sse';

Usage

Just two lines are needed to speed up your Fastify application.

// app.ts
import fastify from 'fastify';
import { serverFactory } from 'fastify-uws'; // Import here

import router from '~/plugins/router';

export default () => {
  const app = fastify({
    logger: {
      transport: {
        target: '@fastify/one-line-logger',
      },
    },
    serverFactory, // And use here
  });

  app.register(router);

  return app;
};
// server.ts
import app from './app';

const server = app();

const start = async () => {
  try {
    await server.listen({
      host: '127.0.0.1',
      port: 3000,
    });
  } catch (err) {
    server.log.error(err);
    process.exit(1);
  }
};

start();

Use Fetch

// src/routes/hello-http/+handler.ts
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from 'typebox';

export default (async (app) => {
  app.get(
    '',
    {
      schema: {
        response: {
          200: Type.Object({
            message: Type.String(),
          }),
        },
      },
    },
    async (req, reply) => {
      return reply.send({
        message: 'Hello, World!',
      });
    },
  );
}) as FastifyPluginAsyncTypebox;

With FormData

// app.ts
import multipart from '@fastify/multipart';

app.register(multipart);
// src/routes/hello-fd/+handler.ts
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import fs from 'node:fs';
import { pipeline } from 'node:stream/promises';

export default (async (app) => {
  app.post('', async (req, reply) => {
    const data = await req.file();

    data.file; // stream
    data.fields; // other parsed parts
    data.fieldname;
    data.filename;
    data.encoding;
    data.mimetype;

    await pipeline(data.file, fs.createWriteStream(data.filename));
    // or
    // await data.toBuffer(); // Buffer

    return reply.send({ message: 'ok' });
  });
}) as FastifyPluginAsyncTypebox;

Use WebSocket

Just a single line of change can speed up your WebSocket application in Fastify.

- import websocket from '@fastify/websocket';
+ import { websocket } from 'fastify-uws';
// app.ts
import { websocket } from 'fastify-uws';

app.register(websocket);
// src/routes/hello-ws/+handler.ts
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';

export default (async (app) => {
  // $ node client-ws.mjs
  app.get('', { websocket: true }, (socket) => {
    app.log.info('Client connected');

    socket.on('message', (message: MessageEvent) => {
      console.log(`Client message: ${message}`);
      socket.send('Hello from Fastify!');
    });

    socket.on('close', () => {
      app.log.info('Client disconnected');
    });
  });
}) as FastifyPluginAsyncTypebox;

Use EventSource

// app.ts
import sse from '@fastify/sse';

app.register(sse);
// src/routes/hello-sse/+handler.ts
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';

export default (async (app) => {
  // $ node client-es.mjs
  app.get('', { sse: true }, async (request, reply) => {
    app.log.info('Client connected');

    await reply.sse.send({ data: 'Hello from Fastify!' });

    request.raw.on('close', () => {
      app.log.info('Client disconnected');
    });
  });
}) as FastifyPluginAsyncTypebox;

TLS/SSL: http2 and https

import fs from 'node:fs';
import fastify from 'fastify';
import { serverFactory, websocket } from 'fastify-uws';
// [...]
export default () => {
  const app = fastify({
    http2: true,
    https: {
      key: fs.readFileSync(process.env.HTTPS_KEY),
      cert: fs.readFileSync(process.env.HTTPS_CERT),
    },
    logger: {
      transport: {
        target: '@fastify/one-line-logger',
      },
    },
    serverFactory,
  });

  app.register(websocket);
  // [...]
};
// [...]

Benchmarks

oha v1.4.5

$ oha -c 500 -z 10s --no-tui http://0.0.0.0:3000/api/hello-world
VersionLanguageRouterRequests/sec
hyper1.4.1Rust56,175.6102
warp0.3.7Rust55,868.5861
axum0.7.7Rust54,588.2828
bun1.1.30TypeScript/Bun54,098.4841
graphul1.0.1Rust53,949.4400
poem3.1.0Rust53,849.0781
uws20.48.0JavaScript/Node52,802.8029
elysia1.1.17TypeScript/Bun52,257.3305
~ 5.5k ~
hyper-express6.17.2JavaScript/Node46,745.4887
hono4.6.3TypeScript/Bun46,685.6014
nhttp2.0.2TypeScript/Deno44,874.2535
deno2.0.0TypeScript/Deno44,753.8552
hono4.6.3TypeScript/Deno43,280.7544
~ 9.2k ~
h31.12.0TypeScript/Bun34,043.4693
fastify-uws1.0.0JavaScript/Node31,295.8715
polka1.0.0-next.28JavaScript/Node31,086.5543
oak17.0.0TypeScript/Deno30,730.7971
node20.18.0JavaScript/Node29,230.1719
oak17.0.0TypeScript/Bun27,449.3417
fastify5.0.0JavaScript/Node27,408.6679
hono4.6.3JavaScript/Node25,138.5659
~ 4.9k ~
h31.12.0JavaScript/Node20,193.2311
~ 9.2k ~
express4.21.0JavaScript/Node10,949.1532

Credits

This project is based on @geut/fastify-uws and is licensed under the MIT License.

Keywords

fastify

FAQs

Package last updated on 18 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts