# kabel

> Server that relays messages to websocket clients (i.e. browsers)

Latest version **0.2.1** (published 2020-09-26) · MIT license · 0 weekly downloads

## Install

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

Provides the command `kabel`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2020-09-26 |
| First published | 2020-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Vidar Eldøy |
| Maintainers | eldoy |

## Links

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

## Dependencies (1)

- [sirloin](https://npm.io/package/sirloin.md) ^0.17.2

## Recent versions

- 0.2.1 (latest) — 2020-09-26
- 0.2.0 — 2020-09-26
- 0.1.1 — 2020-09-25
- 0.1.0 — 2020-09-25

## README

# Kabel
Server that relays messages to websocket clients (i.e. browsers). Useful for sending commands to applications via the command line, for example tell the browser to reload when a file changes.

### Installation
`npm i -g kabel`

### Setup autoreload for your web app

#### Start kabel
```bash
# Default port is 3900
kabel

# With different port as option
kabel -p 3010

# or with env variable
KABEL_PORT=3011 kabel

# You can also set the wait in ms before sending the message
kabel -w 500

# or with env variable
KABEL_WAIT=500 kabel

# Quiet output
kabel -q

# or with env variable
KABEL_QUIET=0
```
You only need one kabel server for all your apps.

#### Set up web socket connection
Include this on in your web app:
```html
<script>
  var ws = new WebSocket('ws://localhost:3900')
  ws.onopen = function() {
    // Change the name to the name of your app
    // The name should match what you're sending with curl
    ws.send(JSON.stringify({ name: 'app' }))
  }
  ws.onmessage = function() {
    window.location.reload(true)
  }
  ws.onerror = function() {
    console.log('Error connecting to kabel')
  }
</script>
```

#### Automatic reload with nodemon
Create a `nodemon.json` file in your app root direcory that looks like this:
kabel.js notify 'http://localhost:3900?name=cfhqadmin'
```json
{
  "events": {
    "restart": "kabel notify 'http://localhost:3900?name=app'"
   }
}
```
Your application will now reload every time nodemon restarts.

Alternatively you can use `curl`:
```json
{
  "events": {
    "restart": "curl -X POST -d 'name=app' http://localhost:3900"
   }
}
```

#### Send a message to the browser via kabel
```
# From terminal using kabel
kabel notify 'http://localhost:3900?name=app'

# From terminal using curl
curl -X POST -d 'name=app' http://localhost:3900
```
Your app should now have reloaded.

### License
MIT licensed. Enjoy!

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