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-httpVerified import paths — ran on the pinned version, not inferred.
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.
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'`.
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.Implement a timer (e.g., `setInterval`) to regularly re-announce your service port and name to the Grenache network (DHT/Grape).
Upgrade your Node.js environment to version 16.0 or newer. Check the `engines` field in `package.json` for exact requirements.
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.
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.
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.