# tiny-buffer-rpc

> Lightweight binary RPC

Latest version **2.4.0** (published 2026-05-05) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install tiny-buffer-rpc
pnpm add tiny-buffer-rpc
yarn add tiny-buffer-rpc
bun add tiny-buffer-rpc
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2026-05-05 |
| First published | 2023-05-09 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 40.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Holepunch |
| Maintainers | mafintosh, andrewosh |

## Links

- npm: https://www.npmjs.com/package/tiny-buffer-rpc
- Repository: https://github.com/holepunchto/tiny-buffer-rpc
- Homepage: https://github.com/holepunchto/tiny-buffer-rpc#readme
- Issues: https://github.com/holepunchto/tiny-buffer-rpc/issues
- npm.io page: https://npm.io/package/tiny-buffer-rpc

## Dependencies (4)

- [b4a](https://npm.io/package/b4a.md) ^1.6.3
- [streamx](https://npm.io/package/streamx.md) ^2.13.2
- [safety-catch](https://npm.io/package/safety-catch.md) ^1.0.2
- [compact-encoding](https://npm.io/package/compact-encoding.md) ^3.0.0

## Recent versions

- 2.4.0 (latest) — 2026-05-05
- 2.3.1 — 2025-08-05
- 2.3.0 — 2025-06-14
- 2.2.2 — 2024-11-19
- 2.2.1 — 2024-10-03
- 2.2.0 — 2024-10-03
- 2.1.1 — 2024-09-02
- 2.1.0 — 2024-03-22
- 2.0.1 — 2023-11-06
- 2.0.0 — 2023-08-09
- 1.1.3 — 2023-08-08
- 1.1.2 — 2023-08-08
- 1.1.1 — 2023-08-02
- 1.1.0 — 2023-08-02
- 1.0.0 — 2023-05-09

## README

# tiny-buffer-rpc

Lightweight binary bi-directional RPC.

### Installation

```
npm i tiny-buffer-rpc
```

### Usage

```js
const RPC = require('tiny-buffer-rpc')
const c = require('compact-encoding')

const rpc1 = new RPC(send1)
const rpc2 = new RPC(send2)

rpc1.register(0, {
  request: c.string,
  response: c.string,
  onrequest: (data) => 'world'
})
const ping = rpc2.register(0, {
  request: c.string,
  response: c.string
})

await ping.request('hello') // 'world'

function send1(data) {
  rpc2.recv(data)
}
function send2(data) {
  rpc1.recv(data)
}
```

### API

#### `const rpc = new RPC(send)`

Construct a new `TinyBufferRPC` instance.

`send` must be a function that takes a `Buffer`, and should handle forwarding requests
between the two sides.

#### `const method = rpc.register(id, opts)`

Register a new RPC method for the given `id`

`id` must be an `Integer` >= 0.

If `onrequest` is provided, this method will be able to handle requests.

The return value of `onrequest` will be encoded with the response encoding, then sent.

If `onrequest` throws, the error will be forwarded back to the requester.

`opts` should include:

```js
{
  request: c.buffer, // The request encoding
  response: c.buffer, // The response encoding
  onrequest: data => { ... } // A request handler
}
```

#### `const response = await method.request(data)`

Send a request.

`data` will be encoded with the request encoding.

#### `method.send(data)`

Unidirectionally send data without expecting a response.

Useful for sending events.

`data` will be encoded with the request encoding.

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