# rawr

> JSON-RPC over simple node style event emitters

Latest version **1.0.1** (published 2026-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install rawr
pnpm add rawr
yarn add rawr
bun add rawr
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2026-01-29 |
| First published | 2013-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Luis Montes |
| Maintainers | monteslu, samrocksc |
| Keywords | rpc, json-rpc, promises, websocket, ws, promise, mqtt |

## Links

- npm: https://www.npmjs.com/package/rawr
- Repository: https://github.com/iceddev/rawr
- Homepage: https://github.com/iceddev/rawr#readme
- Issues: https://github.com/iceddev/rawr/issues
- npm.io page: https://npm.io/package/rawr

## Dependencies (1)

- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.1

## 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

- 1.0.1 (latest) — 2026-01-29
- 1.0.0 — 2026-01-25
- 0.19.0 — 2025-08-11
- 0.18.0 — 2025-07-09
- 0.17.0 — 2025-05-06
- 0.16.0 — 2024-05-20
- 0.15.1 — 2023-06-05
- 0.15.0 — 2021-02-26
- 0.14.0 — 2021-02-25
- 0.13.0 — 2019-11-12
- 0.12.2 — 2019-04-04
- 0.12.1 — 2019-04-02
- 0.12.0 — 2019-04-02
- 0.11.0 — 2019-03-29
- 0.10.0 — 2019-03-27
- … 12 more at https://npm.io/package/rawr/versions

## README

# rawr (a.k.a. RAWRpc)

[![NPM](https://nodei.co/npm/rawr.svg)](https://nodei.co/npm/rawr/)  ![example workflow](https://github.com/iceddev/rawr/actions/workflows/workflow.yml/badge.svg)

Remote Procedure Calls ([JSON-RPC](https://www.jsonrpc.org/specification)) sent over any [EventEmitter](https://nodejs.org/dist/latest-v12.x/docs/api/events.html#events_class_eventemitter)-based transport.  [WebWorkers](/transports/worker), [WebSockets](/transports/websocket), [MQTT](/transports/mqtt), and more!

![RAWRpc](rawr.jpg)

## Installation

`npm install rawr`


## Using rawr with a webworker

Every rawr peer can act as both a client and a server, and make remote method calls in either direction.

For example, we can use methods that belong to a webworker.

#### In our worker.js file:
```javascript
import rawr, { transports } from 'rawr';

// In this instantiation, we can pass in an object to 
// `methods` that is exposed to our web page (see below)
const peer = rawr({
  transport: transports.worker(),
  methods: { calculatePrimes },
});

function calculatePrimes(howMany) {
  // Do something CPU intensive in this thread that
  // would otherwise be too expensive for our web page
  ...
  return primes;
}
```

#### In our web page:
```javascript
import rawr, { transports } from 'rawr';

const myWorker = new Worker('/worker.js');
const peer = rawr({transport: transports.worker(myWorker)});

// Remote methods are *~automatically available~*
const result = await peer.methods.calculatePrimes(349582);
```

The methods are available to the rawr peer through the magic of [Proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)

![Magic](magic.gif)

## Using rawr with a websocket

We could use rawr to make calls to a remote server such as a websocket.
Simply use a different transport.

#### on our web page:
```javascript
import rawr, { transports } from 'rawr';

const socket = new WebSocket('ws://localhost:8080');

socket.onopen = (event) => {
  // create the rawr peer
  const peer = rawr({
    transport: transports.websocket(socket)
  });
};
```

The websocket server could even make *arbitrary calls to the client!*

#### on the server (using [ws](https://github.com/websockets/ws)):
```javascript
import rawr, { transports } from 'rawr';

socketServer.on('connection', (socket) => {
  const peer = rawr({
    transport: transports.websocket(socket)
  });

  const result = await peer.methods.doSomethingOnClient();
});
```

The websocket transport works with both browser WebSocket and Node.js [ws](https://github.com/websockets/ws) library.

## Handling Notifications

Peers can also send each other [notifications](https://www.jsonrpc.org/specification#notification):

```javascript
peer.notifiers.saySomething('hello');
```

Receiving those notifications from another peer is just as simple:
```javascript
peer.notifications.onsaySomething((words) => {
  console.log(words); //hello
});
```


## Transports

Transporst are simply [EventEmitters](https://nodejs.org/dist/latest-v12.x/docs/api/events.html#events_class_eventemitter) that do two things:

They emit ([json-rpc](https://www.jsonrpc.org/specification)) objects on an `rpc` topic when receiving data.
```javascript
transport.emit('rpc', {jsonrpc:'2.0', id: 1, method: 'add', params: [2, 3]});
```

They send rpc objects out.
```javascript
transport.send({jsonrpc:'2.0', id: 1, method: 'subtract', params: [5, 4]});
```

While, websockets, mqtt, and webworkers are common, transports could be built from any form of communication you wish!


## Custom Configuration for Method invocations

if you need to pass configuration specific method invocations, you can uses the `methodsExt` property of a rawr instance.

For example, if you want to specify a specific timeout for a method call you can use a configuration object as the last parameter:
```javascript
try {
  const result = await peer.methodsExt.doSomething(a, b, { timeout: 100 });
} catch(e) {
  // method took longer than a 100 millseconds
}
```

This also works for customizaton of the transport.
For example, you may want to pass configuration for transferable objects to a webWorker:
```javascript
  const result = await peer.methodsExt.processImage({ imageBitmap, stuff }, {
    postMessageOptions: { transfer: [imageBitmap] }
  });
```

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