{"id":48240,"library":"js-rpc2","title":"js-rpc2","description":"A lightweight RPC library for JavaScript/TypeScript enabling client-server communication over HTTP and WebSocket. Supports strings, binary data, objects, arrays, and callbacks for progress feedback. Current stable version is 2.6.1. Integrates with Koa router for server-side setup. Ships TypeScript definitions. Differentiated by simple API and broad data type support, including Uint8Array.","status":"active","version":"2.6.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/yuanliwei/js-rpc","tags":["javascript","js","web","http","websocket","rpc","electron","chrome","extensions","typescript"],"install":[{"cmd":"npm install js-rpc2","lang":"bash","label":"npm"},{"cmd":"yarn add js-rpc2","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-rpc2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for WebSocket server functionality","package":"ws","optional":false},{"reason":"Required for Koa router integration on server side","package":"koa-router","optional":false},{"reason":"Required for Koa application setup","package":"koa","optional":false}],"imports":[{"note":"The package exports from src/client.js directly; main entry may not include this symbol.","wrong":"import { createRpcClientHttp } from 'js-rpc2'","symbol":"createRpcClientHttp","correct":"import { createRpcClientHttp } from 'js-rpc2/src/client.js'"},{"note":"WebSocket client import requires specific path.","wrong":"import { createRpcClientWebSocket } from 'js-rpc2'","symbol":"createRpcClientWebSocket","correct":"import { createRpcClientWebSocket } from 'js-rpc2/src/client.js'"},{"note":"Server-side Koa router import requires specific path.","wrong":"import { createRpcServerKoaRouter } from 'js-rpc2'","symbol":"createRpcServerKoaRouter","correct":"import { createRpcServerKoaRouter } from 'js-rpc2/src/server.js'"}],"quickstart":{"code":"import { createServer } from 'http';\nimport Koa from 'koa';\nimport Router from 'koa-router';\nimport { createRpcServerKoaRouter } from 'js-rpc2/src/server.js';\nimport { createRpcClientHttp } from 'js-rpc2/src/client.js';\n\n// Server\nconst app = new Koa();\nconst router = new Router();\napp.use(router.routes());\napp.use(router.allowedMethods());\ncreateServer(app.callback()).listen(9000);\n\nclass RpcApi {\n  async hello(string, buffer, object, _null, _undefined, array, callback) {\n    for (let i = 0; i < 3; i++) {\n      callback('progress : ', i);\n      await new Promise((resolve) => setTimeout(resolve, 1000));\n    }\n    return [\n      `${typeof string}-${typeof buffer}-${typeof object}-${typeof _null}-${typeof _undefined}-${typeof array}`,\n      new Uint8Array(3),\n      { a: 1, b: 2, c: 3 },\n      1,\n      true,\n      undefined,\n      [1, 2, 3, 4],\n    ];\n  }\n}\nconst extension = new RpcApi();\ncreateRpcServerKoaRouter({ path: '/rpc/abc', router: router, extension: extension });\n\n// Client\nconst rpc = createRpcClientHttp({ url: 'http://127.0.0.1:9000/rpc/abc' });\nlet ret = await rpc.hello('123', new Uint8Array(3), { q: 2, w: 3, e: 4 }, null, undefined, [1, 2, 3, 4], (message, num) => {\n  console.info('callback', message, num);\n});\nconsole.info(ret);","lang":"javascript","description":"Demonstrates setting up a server with Koa and RPC router, and making an RPC call from a client with progress callbacks."},"warnings":[{"fix":"Use correct paths: 'js-rpc2/src/client.js' for client functions, 'js-rpc2/src/server.js' for server functions.","message":"Imports must use specific paths (e.g., 'js-rpc2/src/client.js') instead of the package name. Default main entry may not export these symbols.","severity":"gotcha","affected_versions":">=2.0"},{"fix":"Update imports to include the full path to src/client.js or src/server.js.","message":"Version 2.0 moved client/server functions to src/ subdirectory, breaking direct imports from 'js-rpc2'.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Use named imports from specific subpaths as shown in documentation.","message":"The package does not provide a main export; relying on default import from 'js-rpc2' will return an empty object.","severity":"deprecated","affected_versions":">=2.0"},{"fix":"Ensure callback parameters are always the last in the method signature on the server side.","message":"Callback functions must be the last argument; otherwise, errors may occur during deserialization.","severity":"gotcha","affected_versions":">=2.0"}],"env_vars":null,"search_vec":"'2.6.1':34 'api':50 'array':24 'binari':21 'broad':52 'callback':26 'chrome':65 'client':12 'client-serv':11 'communic':14 'current':30 'data':22,53 'definit':46 'differenti':47 'electron':64 'enabl':10 'extens':66 'feedback':29 'http':16,61 'includ':56 'integr':35 'javascript':58 'javascript/typescript':9 'js':2,59 'js-rpc2':1 'koa':37 'librari':7 'lightweight':5 'object':23 'progress':28 'router':38 'rpc':6,63 'rpc2':3 'server':13,41 'server-sid':40 'setup':43 'ship':44 'side':42 'simpl':49 'stabl':31 'string':20 'support':19,55 'type':54 'typescript':45,67 'uint8array':57 'version':32 'web':60 'websocket':18,62","created_at":"2026-06-07T16:55:36.995839+00:00","updated_at":"2026-06-07T16:55:36.995839+00:00","problems":[{"fix":"Change import to: import { createRpcClientHttp } from 'js-rpc2/src/client.js';","cause":"Importing from incorrect path.","error":"TypeError: (0 , client.createRpcClientHttp) is not a function"},{"fix":"Use import with explicit path: import { ... } from 'js-rpc2/src/client.js';","cause":"TypeScript cannot resolve module because main entry doesn't point to output.","error":"Cannot find module 'js-rpc2' or its corresponding type declarations."},{"fix":"Ensure callback is the last argument and is a function.","cause":"Callback parameter not provided or in wrong position.","error":"Error: callback is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/yuanliwei/js-rpc#readme","github":"ssh://git@github.com/yuanliwei/js-rpc","docs":null,"changelog":null,"pypi":null,"npm":"js-rpc2","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}