{"id":15825320,"url":"https://github.com/remotelib/remote-lib","last_synced_at":"2025-05-12T19:58:46.279Z","repository":{"id":24219140,"uuid":"97914958","full_name":"remotelib/remote-lib","owner":"remotelib","description":"💫 Convert your JavaScript library to a remote service.","archived":false,"fork":false,"pushed_at":"2022-12-06T15:20:25.000Z","size":5349,"stargazers_count":44,"open_issues_count":12,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T08:17:31.788Z","etag":null,"topics":["context","javascript","library","nodejs","p2p","remote","rpc","serverless","webrtc","websocket"],"latest_commit_sha":null,"homepage":"http://www.remotelib.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remotelib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-21T06:39:03.000Z","updated_at":"2025-02-28T09:59:54.000Z","dependencies_parsed_at":"2023-01-14T00:36:07.027Z","dependency_job_id":null,"html_url":"https://github.com/remotelib/remote-lib","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remotelib%2Fremote-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remotelib%2Fremote-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remotelib%2Fremote-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remotelib%2Fremote-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remotelib","download_url":"https://codeload.github.com/remotelib/remote-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253814320,"owners_count":21968555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context","javascript","library","nodejs","p2p","remote","rpc","serverless","webrtc","websocket"],"created_at":"2024-10-05T09:07:44.649Z","updated_at":"2025-05-12T19:58:46.257Z","avatar_url":"https://github.com/remotelib.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"http://www.remotelib.com\"\u003e\u003cimg src=\"https://github.com/remotelib/remote-lib/raw/master/manual/asset/icon.png?docs-hack=.svg\" alt=\"RemoteLib\" width=\"200\"\u003e\u003c/a\u003e\n  \u003cbr\u003e\n  RemoteLib\n  \u003cbr\u003e\n  \u003cbr\u003e\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003eConvert your JavaScript library to a remote service 💫.\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.org/package/remote-lib\"\u003e\u003cimg src=\"http://img.shields.io/npm/v/remote-lib.svg\" alt=\"View On NPM\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/remotelib/remote-lib\"\u003e\u003cimg src=\"https://travis-ci.org/remotelib/remote-lib.svg?branch=master\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/remotelib/remote-lib\"\u003e\u003cimg src=\"https://david-dm.org/remotelib/remote-lib.svg\" alt=\"Dependency Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/remotelib/remote-lib\"\u003e\u003cimg src=\"https://codecov.io/gh/remotelib/remote-lib/branch/master/graph/badge.svg\" alt=\"codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/remote-lib.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\n**RemoteLib** is a library that can be shared remotely with other peers without worrying for API \ninterfaces or RPC integration. Using only a \n[Duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex), such as \n[TCP socket](https://nodejs.org/api/net.html#net_net_createconnection_options_connectlistener), \n[WebSocket](https://www.npmjs.com/package/websocket-stream) or even \n[WebRTC DataChannel](https://www.npmjs.com/package/simple-peer), your users \nwill be able to use your code remotely exactly as if it's local library. This, including calling \nfunctions with callbacks, \n[Promises](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), \nclass inheritance, getters and setters support and more. See [usage](#usage) for some examples.\n\n##### Is it kind of RPC?\nNo. RemoteLib is based on [remote-context](packages/remote-context) and won't just proxying \nyour functions. Instead, you have an entirely shared context between two remote peers. See \n[Features](#features) for more details:\n\n### Features\n\n- **Use RemoteLib on node.js \u0026 on the browser** (just use [browserify](http://browserify.org) or\n [webpack](https://webpack.js.org/) to create a bundle).\n- **Pure Javascript** (Using \n[ES6 Proxy](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy)).\n- **Seamless interface** (your library will be proxies AS IS to the users remotely!). \n- **Proxy anything** - from functions and object, to classes and Promises and even \n[Symbols](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol)!\n- **Builtin support for Promises** - Resolve any path on the remote object via the `RemoteProxy` \ninterface.\n- **Builtin support for class inheritance** - Your user can use `instanceof` with the proxyied \nobjects.\n- **Use any communication method** - connect using simple `Stream` interface \n([WebSocket](https://www.npmjs.com/package/websocket-stream) or \n[WebRTC](https://www.npmjs.com/package/simple-peer) implementation available).\n- Serve **multiple peers** in parallel.\n- Use RemoteLib for **P2P projects** (via the [`remote-context`](packages/remote-context) library). \n\n### Install\n```\nnpm install remote-lib\n```\n\n### Ways to help\n* **Join us in [Gitter](https://gitter.im/remotelib/Lobby)** to help with development or to hang out with some mad science hackers :)\n* **[Create a new issue](https://github.com/remotelib/remote-lib/issues/new)** to report bugs\n* **[Fix an issue](https://github.com/remotelib/remote-lib/issues?state=open)**. RemoteLib is an OPEN Open Source Project!\n\n\n### Getting Started\n\n#### Simple \"Hello World\" library\n\nCreate a context and a server:\n```js\nconst net = require('net');\nconst { Library } = require('remote-lib');\n\n// Create the library context\nconst library = new Library({\n  hello: 'World!',\n});\n\n// Create a server and serve each client the context remotely\nconst server = net.createServer(socket =\u003e {\n  library.serve(socket);\n});\n\n// Bind on port 3000\nserver.listen(3000);\n```\n\nOn the client side, we just need to connect to the server an create our remote library. Notice \nthat the server and the client sharing only a single socket without any knowledge of the server \nlibrary format. You can easily replace the socket it with \n [WebSocket](https://www.npmjs.com/package/websocket-stream) or even \n[WebRTC DataChannel](https://www.npmjs.com/package/simple-peer).\n\n```js\nconst net = require('net');\nconst { RemoteLibrary } = require('remote-lib');\n\n// Connect to the server and get a stream\nconst socket = net.createConnection(3000);\n\n// Create the remote library\nconst remoteLibrary = new RemoteLibrary(socket);\n\n// Get the remote \"hello\" value\nremoteLibrary.hello.then(value =\u003e {\n  // value === 'World!'\n});\n```\n\n#### Calling remote functions\n\nRemoteLib supporting calling remote functions as well:\n\n```js\n// On the server:\nconst library = new Library({\n  // Simple functions\n  foo() {\n     return 'bar';\n  },\n  \n  // Async functions\n  getData: () =\u003e\n    new Promise(resolve =\u003e\n      setTimeout(() =\u003e resolve({ data: 'Tada!' }), 100),\n    ),\n  \n  // Functions with callbacks\n  loadInfo: callback =\u003e {\n    setTimeout(callback(123), 200); // call callback after 200ms\n  },\n  \n  // Functions of functions\n  sum: x =\u003e y =\u003e x + y,\n});\n```\n\n```js\n// On the client:\nremoteLibrary.foo().then(value =\u003e {\n  // value === 'bar' \n});\n\n// Promises already handled for you \nremoteLibrary.getData().then(value =\u003e {\n  // value == { data: 'Tada!' }\n});\n\n// Send callback as first parameter\nremoteLibrary.loadInfo(value =\u003e {\n  // value === 123\n}).catch(err =\u003e {\n  // catch any errors while calling loadInfo()\n});\n\nremoteLibrary.sum(5).then(async sum2 =\u003e {\n  await sum2(2); // 7 \n});\n\n// You can even speed things up by using the virtual-path promise:\nremoteLibrary.sum(3)(2).then(value =\u003e {\n  // value === 5 \n});\n```\n\n#### Using remote classes\nUse can use build-in classes or create one by your own:\n\n```js\n// On the server\nclass MyClass {\n  constructor(i) {\n    this.i = i;\n  }\n  \n  inc() {\n    this.i += 1;\n    return this.i;\n  }\n}\n\nconst library = new Library({\n  myClass: new MyClass(5),\n\n  // native ES6 Set class instance\n  myThings: new Set(['car', 'keys', 'pizza']),\n});\n```\n\n```js\n// On the client:\nremoteLibrary.myClass.then(async myClass =\u003e {\n  // myClass.i === 5\n                \n  // Call methods with async promises\n  await myClass.inc(); // 6\n  // myClass.i === 6 \n});\n\nremoteLibrary.myThings.then(async myThings =\u003e {\n  myThings instanceof Set; // true\n    \n  // Access cached getters instantly\n  myThings.size; // 3\n\n  await myThings.has('keys'); // true\n  await myThings.has('cat'); // false\n\n  await myThings.add('dog');\n  await myThings.has('dog'); // true\n});\n```\n\n#### Handling errors\n\nRemoteLib catch all the errors for you and deliver them back to the user as-if they happens on \nthe client:\n\n```js\n// On the server:\nconst library = new Library({\n  doNotCallMe() {\n     throw ReferenceError('I told you! :)');\n  },\n});\n```\n\n```js\n// On the client:\nremoteLibrary.doNotCallMe().catch(err =\u003e {\n  err instanceof ReferenceError; // true\n  err.message; // \"I told you! :)\"\n});\n\nremoteLibrary.notExistsFunction().catch(err =\u003e {\n  err instanceof TypeError; // true\n  err.message; // \"notExistsFunction is not a function\"\n});\n```\n\n### API Reference\nRemote-lib is build with many small sub-packages, each package implement a small part of this library.\nYou can read here the [full API Reference](http://www.remotelib.com).\n\n| module | version | description |\n|---|---|---|\n| **[remote-lib](packages/remote-lib)** | [![view on npm](http://img.shields.io/npm/v/remote-lib.svg)](https://www.npmjs.org/package/remote-lib) | A high level API for creating remote libraries.\n| **[remote-context](packages/remote-context)** | [![view on npm](http://img.shields.io/npm/v/remote-context.svg)](https://www.npmjs.org/package/remote-context) | The core of `remote-lib`, creating and serving remote context.\n| **[remote-environment](packages/remote-environment)** | [![view on npm](http://img.shields.io/npm/v/remote-environment.svg)](https://www.npmjs.org/package/remote-environment) | A shared environment context between remote peers.\n| **[remote-instance](packages/remote-instance)** | [![view on npm](http://img.shields.io/npm/v/remote-instance.svg)](https://www.npmjs.org/package/remote-instance) | A stream transformer that can parse and `construct` instances remotely.\n| **[remote-protocol](packages/remote-protocol)** | [![view on npm](http://img.shields.io/npm/v/remote-protocol.svg)](https://www.npmjs.org/package/remote-protocol) | The core of `remote-context` protocol.\n| **[reference-context](packages/reference-context)** | [![view on npm](http://img.shields.io/npm/v/reference-context.svg)](https://www.npmjs.org/package/reference-context) | Virtual context implementation on vanilla Javascript.\n\n\n### License\n\n\u0026copy; 2017 Moshe Simantov\n\nLicensed under the [Apache License, Version 2.0](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremotelib%2Fremote-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremotelib%2Fremote-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremotelib%2Fremote-lib/lists"}