kkRPC
A TypeScript-first RPC library that enables seamless bi-directional communication between processes. Call remote functions as if they were local, with full TypeScript type safety and autocompletion support.



Supported Environments
- stdio: RPC over stdio between any combinations of Node.js, Deno, Bun processes
- web: RPC over
postMessage
API and message channel between browser main thread and web workers, or main thread and iframe- Web Worker API (web standard) is also supported in Deno and Bun, the main thread can call functions in worker and vice versa.
- http: RPC over HTTP like tRPC
- supports any HTTP server (e.g. hono, bun, nodejs http, express, fastify, deno, etc.)
- WebSocket: RPC over WebSocket
The core of kkrpc design is in RPCChannel
and IoInterface
.
RPCChannel
is the bidirectional RPC channelLocalAPI
is the APIs to be exposed to the other side of the channelRemoteAPI
is the APIs exposed by the other side of the channel, and callable on the local siderpc.getAPI()
returns an object that isRemoteAPI
typed, and is callable on the local side like a normal local function call.IoInterface
is the interface for implementing the IO for different environments. The implementations are called adapters.- For example, for a Node process to communicate with a Deno process, we need
NodeIo
andDenoIo
adapters which implementsIoInterface
. They share the same stdio pipe (stdin/stdout
). - In web, we have
WorkerChildIO
andWorkerParentIO
adapters for web worker,IframeParentIO
andIframeChildIO
adapters for iframe.
- For example, for a Node process to communicate with a Deno process, we need
In browser, import from
kkrpc/browser
instead ofkkrpc
, Deno adapter uses node:buffer which doesn't work in browser.
Examples
Below are simple examples.
Stdio Example
Web Worker Example
HTTP Example
Codesandbox: https://codesandbox.io/p/live/4a349334-0b04-4352-89f9-cf1955553ae7
api.ts
Define API type and implementation.
server.ts
Server only requires a one-time setup, then it won't need to be touched again.
All the API implementation is in api.ts
.
client.ts
Chrome Extension Example
background.ts
content.ts
How is this guide?