Registry / web-framework / grenache-nodejs-http

grenache-nodejs-http

JSON →
library1.0.1jsnpmunverified

Grenache Node.js HTTP implementation, currently at stable version 1.0.1, is a specialized micro-framework designed for building performant microservices in Node.js environments. It stands out by utilizing Distributed Hash Tables (DHT), similar to those found in Bittorrent, to facilitate peer-to-peer connections rather than traditional centralized brokers. This package provides the HTTP transport layer for Grenache, enabling the creation of RPC servers and clients that announce and discover services over an overlay network managed by external 'Grape' DHT nodes. Its release cadence follows the broader Grenache ecosystem. Key differentiators include its decentralized service discovery, direct peer-to-peer communication, and focus on optimized performance, moving beyond conventional request-response patterns by leveraging a robust, distributed network infrastructure. It specifically abstracts away the complexities of DHT interaction for HTTP-based service communication.

npm install grenache-nodejs-http
INSTALL
IMPORT
SIG · GRENACHE-NODEJS-HT
G
grenache-nodejs-http
web-frameworkjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

PeerRPCServer
const { PeerRPCServer } = require('grenache-nodejs-http')
import { PeerRPCServer } from 'grenache-nodejs-http'
This package is CommonJS-only in its current stable version (1.x). Attempting to use ESM import syntax will result in errors.
PeerRPCClient
const { PeerRPCClient } = require('grenache-nodejs-http')
import PeerRPCClient from 'grenache-nodejs-http'
Grenache services are typically accessed via named imports (destructuring) from the main package object. This package is CommonJS-only.
GrenacheHttpModule
const GrenacheHttp = require('grenache-nodejs-http')
While possible to import the entire module, it's more common to destructure PeerRPCServer and PeerRPCClient directly from the required object for clarity and direct access.

This example demonstrates how to set up two Grenache Grape DHT instances, create a Grenache RPC server that announces a service, and an RPC client that requests data from it over HTTP.

/* Before running this code, you need to install grenache-grape globally: npm i -g grenache-grape Then, start two Grape instances: grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002' grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001' */ const Link = require('grenache-nodejs-link') const { PeerRPCServer, PeerRPCClient } = require('grenache-nodejs-http') // RPC Server const serverLink = new Link({ grape: 'http://127.0.0.1:30001' }) serverLink.start() const peerServer = new PeerRPCServer(serverLink, { timeout: 300000 }) peerServer.init() const service = peerServer.transport('server') // Use Math.floor(Math.random()) for port generation, replacing _.random service.listen(Math.floor(Math.random() * 1000) + 1024) setInterval(() => { serverLink.announce('rpc_test', service.port, {}) }, 1000) service.on('request', (rid, key, payload, handler) => { console.log(`Server received request for '${key}' with payload: '${payload}'`) handler.reply(null, 'world') }) console.log(`RPC Server listening on port ${service.port} and announcing 'rpc_test'`) // RPC Client const clientLink = new Link({ grape: 'http://127.0.0.1:30001' }) clientLink.start() const peerClient = new PeerRPCClient(clientLink, {}) peerClient.init() peerClient.request('rpc_test', 'hello', { timeout: 10000 }, (err, data) => { if (err) { console.error('Client error:', err) process.exit(-1) } console.log(`Client received data: '${data}'`) // world // In a real application, you might want to stop links gracefully // clientLink.stop() // serverLink.stop() // process.exit(0) }) console.log('RPC Client sending request to \'rpc_test\' service...')
Debug
Known issues
gotchaGrenache requires external 'Grape' DHT instances to be running and accessible for service discovery and communication. This is a runtime dependency, not an npm installation.
fix
Install 'grenache-grape' globally (npm i -g grenache-grape) and start at least two instances on different ports, bootstrapping them to each other, e.g., `grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'`.
affects: >=1.0.0
gotchaThe PeerRPCServer's 'stream' event is emitted immediately upon request arrival, while the 'request' event buffers the entire payload before emission. If 'disableBuffered' is true, the 'request' event must be manually triggered or handled.
fix
Choose the appropriate event listener based on whether you need streaming capabilities ('stream') or buffered payload access ('request'). If 'disableBuffered' is active, implement manual buffering logic for 'request' if needed.
affects: >=1.0.0
gotchaService announcements made via 'link.announce()' are ephemeral in the DHT. To ensure continuous service availability, announcements must be re-issued periodically, typically using a setInterval.
fix
Implement a timer (e.g., `setInterval`) to regularly re-announce your service port and name to the Grenache network (DHT/Grape).
affects: >=1.0.0
breakingThis package explicitly requires Node.js version 16.0 or higher, as indicated by the `engines` field in `package.json`. Running on older versions may lead to unexpected errors or failure to start.
fix
Upgrade your Node.js environment to version 16.0 or newer. Check the `engines` field in `package.json` for exact requirements.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Timeout
The RPC client did not receive a response from the service within the specified timeout, often due to the service not being announced or not responding in time.
fix
Ensure the RPC server is running and has successfully announced its service to the Grape network. Check Grape connectivity from both client and server, and increase the timeout if the service is known to have long processing times.
Error: connect ECONNREFUSED 127.0.0.1:30001
The Grenache Link instance was unable to connect to the specified Grape (DHT) node. This usually means Grape is not running or is inaccessible.
fix
Verify that the Grape instance is running on the specified IP address and port, and that no firewall is blocking the connection. Double-check the 'grape' option in the Link constructor.
ReferenceError: PeerRPCServer is not defined
Attempted to use `PeerRPCServer` (or `PeerRPCClient`) without correctly requiring/importing it, or using an incorrect import style for CommonJS.
fix
For CommonJS, use `const { PeerRPCServer } = require('grenache-nodejs-http')` or `const PeerRPCServer = require('grenache-nodejs-http').PeerRPCServer`. This package does not support ESM imports in its current major version.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
grenache-nodejs-linkrequiredProvides the core Grenache Link functionality, essential for connecting to the DHT (Grape) and managing peer communication, which is utilized by the HTTP server and client.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
grenache-nodejs-http — npm install grenache-nodejs-http · libregistry