# @webvpn/net

> Node's net module for a web page, with its sockets on a WebVPN relay

Latest version **0.5.0** (published 2026-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @webvpn/net
pnpm add @webvpn/net
yarn add @webvpn/net
bun add @webvpn/net
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2026-11-27 |
| First published | 2024-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 119.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | banou26 |
| Keywords | webvpn, net, tcp, sockets, browser, polyfill |

## Links

- npm: https://www.npmjs.com/package/@webvpn/net
- Repository: https://github.com/banou26/webvpn
- Homepage: https://webvpn.dev
- Issues: https://github.com/banou26/webvpn/issues
- npm.io page: https://npm.io/package/@webvpn/net

## Dependencies (4)

- [events](https://npm.io/package/events.md) ^3.3.0
- [@types/node](https://npm.io/package/@types/node.md) ^25.9.5
- [@webvpn/client](https://npm.io/package/@webvpn/client.md) ^0.5.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^4.7.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2026-11-27
- 0.4.2 — 2026-06-12
- 0.3.7 — 2026-05-16
- 0.3.6 — 2026-05-16
- 0.3.4 — 2026-05-12
- 0.3.3 — 2026-05-12
- 0.3.1 — 2026-05-12
- 0.2.0 — 2025-01-01
- 0.0.1 — 2024-08-04

## README

# @webvpn/net

Node's `net` module for a web page, with every TCP connection and server on a WebVPN relay through a
`@webvpn/client` session. Code written for Node's `net`, such as a torrent engine or an IRC client, runs in the page
as it is.

## Use

```sh
npm install @webvpn/client @webvpn/net
```

```js
import { connect as openSession } from '@webvpn/client'
import net, { setProvider } from '@webvpn/net'

// the session opens at the first socket; a session already open is taken too
setProvider(() => openSession({ url: 'https://relay.example:4433', webSocketUrl: 'wss://relay.example:8443' }))

const socket = net.connect(6667, 'irc.example')
socket.on('data', (data) => console.log(data.toString()))
socket.write('NICK page\r\n')
```

`createNet(session)` builds a copy of the module of its own, on that session alone.

## Alias `net` to it

With Vite:

```js
export default {
  resolve: { alias: { net: '@webvpn/net', 'node:net': '@webvpn/net' } },
}
```

webpack and esbuild have the same setting, `resolve.alias` and `alias`. The package brings the browser builds of
`stream` and `events` it needs (`readable-stream` and `events`), so the page needs no Node polyfills for it.

## What it does not have

- IPC paths and file descriptors.
- `server.getConnections`, `maxConnections` and `connections`; `BlockList`, `SocketAddress` and `Stream`; the auto
  family selection settings.
- The `lookup` event, and `connect` options other than `host`, `port` and `allowHalfOpen`.
- The relay looks host names up, A records only, and needs its `DNS` feature for them; a server needs its `LISTEN`
  feature.
- A failed connect to a host name names the host in its message, where Node names the address it tried, and has no
  `address`: the relay does not say which address of the name it tried.
- `server.close()` emits `close` once the relay closed the listener, without waiting for the accepted sockets to end.
- `bytesWritten` counts what the relay took, not what waits in the buffer.
- A socket option set before `connect`, or one the relay refuses, emits `error`. `setTypeOfService` keeps the value
  but does not send it.

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