JSON-RPC 2.0 server and client library supporting HTTP, TCP, and WebSocket transports for Node.js. Version 2.0.0 (latest) uses native EventEmitter and enforces RFC-compliant request id types (String, Number, or null). Released under MIT license with moderate maintenance cadence. Differentiators include simple API, built-in authentication for TCP sockets, class extension via ES5Class mixins, and WebSocket support out of the box. Requires Node >= 10.
npm install json-rpc2No compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an HTTP+WebSocket JSON-RPC 2.0 server with an 'add' method and a client that calls it.
Ensure all request ids are String, Number, or null.
Do not depend on EventEmitter3-specific APIs; use standard EventEmitter patterns.
Consider migrating to alternatives like 'jayson' or 'json-rpc-2.0'.
Use default import: `import rpc from 'json-rpc2'` then access `rpc.Server`.
Pass only hostname and port separately: `Client.$create(8000, 'localhost')`.
Change to `import rpc from 'json-rpc2'` then use `rpc.Server`.
Ensure id is a string, number, or null as per JSON-RPC 2.0 spec.
Create a raw server with `rpc.Server.$create()` and then call `server.listenRaw(8080, 'localhost')`.
Use `const rpc = require('json-rpc2')` or `import rpc from 'json-rpc2'`.