pocketcache-sub
v0.0.2
Published
Lightweight subscriber client for pocketcache
Readme
pocketcache-sub
Lightweight SSE subscriber client for pocketcache.
Use this when you only need to listen to events — no server binary, no store API, just subscribe.
npm install pocketcache-sub
# or
pnpm add pocketcache-subQuick start
import { PocketCacheSub } from "pocketcache-sub";
const sub = new PocketCacheSub({ authKey: "my-secret", port: 8287 });
const unsub = sub.subscribe("orders", (event) => {
console.log(event.channel); // "orders"
console.log(event.data); // parsed payload
});
// Later
unsub();API
new PocketCacheSub(options)
| Option | Type | Default | Description |
|---|---|---|---|
| authKey | string | required | Sent as X-Server-Key on every request |
| host | string | "localhost" | Host of the pocketcache server |
| port | number | 8287 | Port of the pocketcache server |
PocketCacheSub has no spawn() method — it connects to an already-running pocketcache instance.
sub.subscribe(channel, callback)
Opens an SSE connection to the given channel. Returns an UnsubscribeFn — call it to disconnect.
const unsub = sub.subscribe("payments", (event) => {
// event.channel — the channel name
// event.data — the parsed JSON payload
});
unsub(); // disconnectsub.subscribeMany(channels, callback)
Subscribe to multiple channels with a single callback. The event.channel field tells you which one fired.
const unsub = sub.subscribeMany(["orders", "inventory"], (event) => {
if (event.channel === "orders") { /* ... */ }
if (event.channel === "inventory") { /* ... */ }
});
unsub(); // disconnects allCLI
pocketcache-sub --authkey=my-secret --port=8287 --channels=orders,inventoryPrints received events as JSON to stdout:
{ "channel": "orders", "data": { "id": 123 } }See also
pocketcache — full client with spawn, key-value, hashes, counters, and pub/sub.
