# node-quic-client

> A simple Quic protocol client for NodeJS

Latest version **0.3.0** (published 2024-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-quic-client
pnpm add node-quic-client
yarn add node-quic-client
bun add node-quic-client
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2024-09-20 |
| First published | 2024-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 64.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Maintainers | jantje19 |
| Keywords | quic, udp, protocol |

## Links

- npm: https://www.npmjs.com/package/node-quic-client
- Repository: https://github.com/jantje19/node-quic-client
- Homepage: https://github.com/jantje19/node-quic-client#readme
- Issues: https://github.com/jantje19/node-quic-client/issues
- npm.io page: https://npm.io/package/node-quic-client

## Dependencies (1)

- [@mapbox/node-pre-gyp](https://npm.io/package/@mapbox/node-pre-gyp.md) ^1.0.11

## Recent versions

- 0.3.0 (latest) — 2024-09-20
- 0.2.0 — 2024-05-09
- 0.1.3 — 2024-04-28
- 0.1.2 — 2024-04-21
- 0.1.1 — 2024-04-21
- 0.1.0 — 2024-04-13

## README

# node-quic-client

A simple Quic protocol client for NodeJS written in Rust. Internally it uses the awesome [Quinn crate](https://crates.io/crates/quinn).

Because the Quinn crate uses [rustls](https://crates.io/crates/rustls) for cryptography and not OpenSSL (like NodeJS), this may result in some difference in behavior between `node-quic-client` and [the native NodeJS TLS stack](https://nodejs.org/api/tls.html).

This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).

## Prebuilds

This package has three prebuilds: Windows (x64), Linux (x64 & ARM64), and MacOS (ARM64). Other platforms fall back to building from source. This requires the Rust compiler (along with Cargo) to be installed on your system. The `rustup` installer will set all this up for you. Follow the instructions on [the official Rust lang website](https://www.rust-lang.org/learn/get-started).

## Example

```ts
import * as quic from "node-quic-client";

const connection = await quic.connect({
  hostname: "cloudflare.com",
  port: 443,
  alpnProtocols: ["h3"],
  onError(err) {
    console.error("Connection error");
    console.error(err);
  },
  onClose(reason) {
    console.log("Connection closed: " + reason);
  },
  onStream(partialStream) {
    const stream = partialStream.initialize({
      onError: console.error,
      onClose: () => {},
      onData: () => {},
    });

    console.log("New stream. Closing immediately...");
    stream
      .close()
      .catch((err) => console.error("Error while closing the stream: " + err));
  },
});

const stream = await connection.createStream({
  onError(err) {
    console.error("Stream error");
    console.error(err);
  },
  onClose(reason) {
    console.log("Stream closed: " + reason);
    this.getConnection().close(0).catch(console.error);
  },
  onData(data) {
    console.log("Received packet", Buffer.from(data).toString("hex"));
    this.close().catch(console.error);
  },
});

await stream.write(Buffer.from("Hello"));
```

Please note that this example sends `'Hello, World!'` to the cloudflare.com website. This is not a valid HTTP/3 packet and causes the website to never send back a result.

## Building the project

### Installing node-quic-client

Installing node-quic-client requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).

You can install the project with [PNPM](https://pnpm.io). In the project directory, run:

```sh
$ pnpm install
```

This fully installs the project, including installing any dependencies and running the build.

### Building node-quic-client

If you have already installed the project and only want to run the build, run:

```sh
$ npm run build-debug
```

This command uses the [cargo-cp-artifact](https://github.com/neon-bindings/cargo-cp-artifact) utility to run the Rust build and copy the built library into `./lib/index.node`.

### Exploring node-quic-client

After building node-quic-client, you can explore its exports at the Node REPL:

```sh
$ npm install
$ node
> require('.')
```

### Available Scripts

In the project directory, you can run:

#### `pnpm install`

Installs the project, including running `pnpm run build`.

#### `pnpm build`

Builds the Node addon (`index.node`) from source.

Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `pnpm build-*` commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html):

```
pnpm run build -- --feature=beetle
```

##### `pnpm build-release`

Same as [`pnpm build-debug`](#npm-build) but, builds the module with the [`release`](https://doc.rust-lang.org/cargo/reference/profiles.html#release) profile. Release builds will compile slower, but run faster.

#### Tests

Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/).

### Learn More

To learn more about Neon, see the [Neon documentation](https://neon-bindings.com).

To learn more about Rust, see the [Rust documentation](https://www.rust-lang.org).

To learn more about Node, see the [Node documentation](https://nodejs.org).

---
_Source: https://npm.io/package/node-quic-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
