# pushradar

> PushRadar's official Node.js server library.

Latest version **3.1.1** (published 2022-06-26) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2022-06-26 |
| First published | 2017-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | PushRadar |
| Maintainers | pushradar |
| Keywords | pushradar, realtime, real-time, real time, websockets, channels, publish, messages |

## Links

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

## Dependencies (1)

- [got](https://npm.io/package/got.md) ^11.8.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

- 3.1.1 (latest) — 2022-06-26
- 3.1.0 — 2021-04-06
- 3.0.0 — 2021-02-18
- 3.0.0-alpha.1 — 2021-02-08
- 2.0.6 — 2019-07-14
- 2.0.5 — 2019-07-14
- 2.0.4 — 2019-07-14
- 2.0.3 — 2019-07-06
- 2.0.2 — 2019-07-04
- 2.0.1 — 2019-07-04
- 2.0.0 — 2019-07-04
- 1.8.5 — 2019-07-04
- 1.8.4 — 2019-07-04
- 1.8.3 — 2019-07-04
- 1.8.0 — 2019-07-04
- … 4 more at https://npm.io/package/pushradar/versions

## README

<p align="center"><a href="https://pushradar.com" target="_blank"><img src="https://pushradar.com/images/logo/pushradar-logo-dark.svg" width="300"></a></p>

<p align="center">
    <a href="https://www.npmjs.com/package/pushradar"><img src="https://img.shields.io/npm/v/pushradar?cacheSeconds=60&color=5b86e5"></a> 
    <a href="https://www.npmjs.com/package/pushradar"><img src="https://img.shields.io/npm/dt/pushradar?cacheSeconds=60&color=5b86e5"></a>
    <a href="https://www.npmjs.com/package/pushradar"><img src="https://img.shields.io/npm/l/pushradar?cacheSeconds=60&color=5b86e5"></a>
</p>
<br />

## PushRadar Node.js Server Library

[PushRadar](https://pushradar.com) is a realtime API service for the web. The service uses a simple publish-subscribe model, allowing you to broadcast "messages" on "channels" that are subscribed to by one or more clients. Messages are pushed in realtime to those clients.

This is PushRadar's official Node.js server library.

## Prerequisites

In order to use this library, please ensure that you have the following:

- Node.js and npm installed on your server
- A PushRadar account - you can sign up at [pushradar.com](https://pushradar.com)

## Installation

The easiest way to get up and running is to install the library using the npm dependency manager. Run the following command in your console:

```bash
$ npm install pushradar --save
```

## Broadcasting Messages

```javascript
const radar = require("pushradar")("your-secret-key");
radar.broadcast("channel-1", {message: 'Hello world!'});
```

## Receiving Messages

```html
<script src="https://js.pushradar.com/v3/pushradar.min.js"></script>
<script>
    var radar = new PushRadar('your-public-key');
    radar.subscribe.to('channel-1', function (data) {
        console.log(data.message);
    });
</script>
```

## Private Channels

Private channels require authentication and start with the prefix **private-**. We recommend that you use private channels by default to prevent unauthorised access to channels.

You will need to set up an authentication endpoint that returns a token using the `auth(...)` method if the user is allowed to subscribe to the channel. For example:

```javascript
const radar = require("pushradar")("your-secret-key");
const channelName = request.query.channelName;
const socketID = request.query.socketID;
if (/* is user allowed to access channel? */ true) {
    radar.auth(channelName, socketID, (err, authResponse) => {
        if (!err) {
            response.send({token: authResponse.token});
        } else {
            response.status(403);
        }
    });
}
```

Then register your authentication endpoint by calling the `auth(...)` method client-side:

```javascript
radar.auth('/auth');
```

## Presence Channels

Presence channels require authentication and start with the prefix **presence-**. Presence channels are eligible for 'presence messages' containing information about channel subscribers.

You will need to set up an authentication endpoint as with private channels (see above). You should then register a `onPresence(...)` callback which will be called periodically. Your callback should accept two parameters: subscriber count and subscriber data. For example:

```javascript
radar.auth('/auth');
radar.call.on.connection('/connected');

radar.subscribe.to('presence-channel-1', function (data) {
    console.log(data.message);
}).onPresence(function (count, clientData) {
    console.log(count);
});
```

If you wish to pass through subscriber (client) data, you can set up an endpoint and pass its URL to the `call.on.connection(...)` method. Your endpoint will be called when a user first connects to the service. From your endpoint you can register client data as follows:

```javascript
const radar = require("pushradar")("your-secret-key");
const socketID = request.body.socketID;
radar.registerClientData(socketID, {'##uniqueID': 1, 'name': 'James Smith'});
```

## Complete Documentation

Complete documentation for PushRadar's Node.js server library can be found at: <https://pushradar.com/docs/3.x/node>

## License

Copyright © 2021, PushRadar. PushRadar's Node.js server library is licensed under the MIT license:
<https://opensource.org/licenses/mit-license.php>

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