Registry / messaging / grenache-nodejs-ws

grenache-nodejs-ws

JSON →
library1.0.0jsnpmunverified

Grenache is a micro-framework for connecting microservices using Distributed Hash Tables (DHT) for peer-to-peer connections. This package provides WebSocket transport for Node.js. Current stable version is 1.0.0, released with active maintenance. Key differentiators: built-in SSL support, DHT-based service discovery, and optimized performance for microservice communication. Requires Grenache Grape (DHT nodes) to operate. Designed for high-performance P2P RPC with minimal overhead.

npm install grenache-nodejs-ws
INSTALL
IMPORT
SIG · GRENACHE-NODEJS-WS
G
grenache-nodejs-ws
messagingjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PeerRPCServer
const { PeerRPCServer } = require('grenache-nodejs-ws')
const PeerRPCServer = require('grenache-nodejs-ws')
CommonJS default import returns an object containing constructors, use destructuring.
PeerRPCClient
const { PeerRPCClient } = require('grenache-nodejs-ws')
import { PeerRPCClient } from 'grenache-nodejs-ws'
Package uses CommonJS; ESM import may fail. Use require() in Node.js environments.
Link
const Link = require('grenache-nodejs-link')
const { Link } = require('grenache-nodejs-link')
Link is the default export of grenache-nodejs-link, not a named export.

Demonstrates setting up a Grenache RPC server that announces a service via DHT and replies with 'world'.

const Link = require('grenache-nodejs-link'); const { PeerRPCServer } = require('grenache-nodejs-ws'); const link = new Link({ grape: 'http://127.0.0.1:30001' }); link.start(); const peer = new PeerRPCServer(link, {}); peer.init(); const service = peer.transport('server'); const port = Math.floor(Math.random() * 1000) + 1024; service.listen(port); setInterval(() => { link.announce('rpc_test', service.port, {}); }, 1000); service.on('request', (rid, key, payload, handler) => { console.log('Received:', payload); handler.reply(null, 'world'); });
Debug
Known issues
gotchaGrenache requires running Grape DHT nodes. Without them, service discovery fails.
fix
Start Grenache Grape nodes as described in the README before running your application.
affects: >=0.0.0
gotchaThe transport port in listen() must be unique across services. A random port is recommended.
fix
Use a random port or ensure no port conflicts when calling service.listen()
affects: >=0.0.0
gotchaLink must be started before creating PeerRPCClient or PeerRPCServer, otherwise pending requests may fail.
fix
Always call link.start() before peer.init()
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Link is not a constructor
Incorrect import of grenache-nodejs-link as named export
fix
Use `const Link = require('grenache-nodejs-link')` (default import)
Error: listen EADDRINUSE :::<port>
Port already in use when calling service.listen()
fix
Use a dynamically generated port via `_.random(1000) + 1024` or ensure the port is available
Error: connect ECONNREFUSED 127.0.0.1:30001
Grenache Grape is not running or its endpoint is misconfigured
fix
Verify Grape is running on the specified host:port and reachable
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
grenache-graperequiredRequired to run DHT nodes for service discovery
grenache-nodejs-linkrequiredCore library for DHT link management
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
grenache-nodejs-ws — npm install grenache-nodejs-ws · libregistry