{"id":15743840,"url":"https://github.com/doowb/firebase-rpc","last_synced_at":"2025-03-13T10:31:01.785Z","repository":{"id":57236652,"uuid":"75033133","full_name":"doowb/firebase-rpc","owner":"doowb","description":"Asynchronously execute remote functions through firebase.","archived":false,"fork":false,"pushed_at":"2016-11-29T02:08:14.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T11:06:13.447Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-29T02:07:44.000Z","updated_at":"2017-03-21T14:34:30.000Z","dependencies_parsed_at":"2022-08-26T14:11:56.561Z","dependency_job_id":null,"html_url":"https://github.com/doowb/firebase-rpc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Ffirebase-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Ffirebase-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Ffirebase-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Ffirebase-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/firebase-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243385900,"owners_count":20282645,"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":[],"created_at":"2024-10-04T03:21:38.377Z","updated_at":"2025-03-13T10:31:01.494Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# firebase-rpc [![NPM version](https://img.shields.io/npm/v/firebase-rpc.svg?style=flat)](https://www.npmjs.com/package/firebase-rpc) [![NPM downloads](https://img.shields.io/npm/dm/firebase-rpc.svg?style=flat)](https://npmjs.org/package/firebase-rpc)\n\n\u003e Asynchronously execute remote functions through firebase.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save firebase-rpc\n```\n\n## Usage\n\n### Server\n\n```js\n// using `firebase-admin` for example, but this may be `firebase`\nvar firebase = require('firebase-admin');\n\n// initialize firebase using the server credentials file from your firebase console\nfirebase.initializeApp({\n  credential: require('./config.json'),\n  databaseURL: 'your-firebase-url.firebaseio.com'\n});\n\n// create a firebase reference to pass to the server for storing queues and data\nvar ref = firebase.database.ref('path/to/my/ref');\n\nvar Server = require('firebase-rpc').Server;\nvar server = new Server({ref: ref});\n\n// Add some tasks\n// These are `composer` tasks and follow the same conventions as `assemble`, `generate`, and `verb`\nserver.task('foo', function(cb) {\n  // data passed in from the client is on the `this.options` object\n  var foo = this.options.foo || 'foo';\n  cb(null, {foo: foo.toUpperCase()});\n});\n\nserver.task('bar', function(cb) {\n  // data passed in from the client is on the `this.options` object\n  var bar = this.options.bar || 'bar';\n  cb(null, {bar: bar.toUpperCase()});\n});\n\n// start listening to the task queue tasks to execute\nserver.listen();\n```\n\n### Client\n\n```js\n// using `firebase-admin` for example, but this may be the `firebase` web api\nvar firebase = require('firebase-admin');\n\n// Initialize firebase using the server credentials file from your firebase console (use the web config if using in a web browser)\nfirebase.initializeApp({\n  credential: require('./config.json'),\n  databaseURL: 'your-firebase-url.firebaseio.com'\n});\n\n// Create a firebae reference to pass to the client. This should be the same reference the server is using\nvar ref = firebase.database.ref('path/to/my/ref');\n\nvar Client = require('firebase-rpc').Client;\nvar client = new Client({ref: ref});\n\n// run a task\nclient.run('foo', {foo: 'this is foo'}, function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n  //=\u003e { foo: 'THIS IS FOO' }\n});\n```\n\n## API\n\n### [Server](lib/server.js#L25)\n\nCreate a server instance that creates a [firebase-queue](https://github.com/firebase/firebase-queue) instance to use for executing remote functions. Remote functions may be added to the server instance or through built-in commands from a client.\n\n**Example**\n\n```js\nvar config = {\n  ref: firebase.database().ref('path/to/rpc')\n};\n\nvar server = new Server(config);\n```\n\n**Params**\n\n* `config` **{Object}**: Configuration object containing the [firebase](https://firebase.google.com/) database reference and additional options to configure the server.\n* `config.ref` **{Object}**: [firebase](https://firebase.google.com/) database reference specifying where firebase-rpc should store information ([firebase-queue](https://github.com/firebase/firebase-queue) and function results)\n* `config.queue` **{Object}**: Additional [firebase-queue](https://github.com/firebase/firebase-queue) options to specify the number of workers and schemas to use (See [firebase-queue](https://github.com/firebase/firebase-queue) for available options)\n\n### [.listen](lib/server.js#L61)\n\nStart listening by creating a [firebase-queue](https://github.com/firebase/firebase-queue) instance.\n\n**Example**\n\n```js\nserver.listen();\n```\n\n**Params**\n\n* `options` **{Object}**: Additional options to override default [firebase-queue](https://github.com/firebase/firebase-queue) options passed into the constructor.\n* `returns` **{Object}**: Instance of [firebase-queue](https://github.com/firebase/firebase-queue);\n\n### [Client](lib/client.js#L25)\n\nCreate a client instance that adds tasks to a [firebase-queue](https://github.com/firebase/firebase-queue) and listens for results.\n\n**Example**\n\n```js\nvar config = {\n  ref: firebase.database().ref('path/to/rpc')\n};\n\nvar client = new Client(config);\n```\n\n**Params**\n\n* `config` **{Object}**: Configuration object containing the [firebase](https://firebase.google.com/) database reference and additional options to configure the client.\n* `config.ref` **{Object}**: [firebase](https://firebase.google.com/) database reference specifying where firebase-rpc should store information ([firebase-queue](https://github.com/firebase/firebase-queue) and function results)\n\n### [.connect](lib/client.js#L58)\n\nConnect to the [firebase](https://firebase.google.com/) database by setting up client metadata to let the server know if this client is connected or not. When the client disconnects, the metadata is removed. This is called in the [run][#run] method to ensure the client is connected before trying to execute any functions.\n\n**Example**\n\n```js\nclient.connect();\n```\n\n### [.run](lib/client.js#L92)\n\nRun the specified server side task given the specified data and wait for the results.\n\n**Example**\n\n```js\nclient.run('foo', {foo: 'bar'}, function(err, results) {\n  if (err) return console.error(err);\n  console.log(results);\n  //=\u003e {foo: 'BAR'}\n});\n```\n\n**Params**\n\n* `name` **{String}**: Name of the task to run on the server. Task must already be registered with the server.\n* `data` **{Object}**: Optional data to pass to the server side task for running.\n* `cb` **{Function}**: Callback function to be called when the server returns with results.\n\n## About\n\n### Related projects\n\n* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble \"Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit\")\n* [composer](https://www.npmjs.com/package/composer): API-first task runner with three methods: task, run and watch. | [homepage](https://github.com/doowb/composer \"API-first task runner with three methods: task, run and watch.\")\n* [firebase-cron](https://www.npmjs.com/package/firebase-cron): Store and run cron jobs with firebase. | [homepage](https://github.com/doowb/firebase-cron \"Store and run cron jobs with firebase.\")\n* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate \"Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.\")\n* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb \"Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](contributing.md) for avice on opening issues, pull requests, and coding standards.\n\n### Building docs\n\n_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_\n\nTo generate the readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install -g verb verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n### Author\n\n**Brian Woodward**\n\n* [github/doowb](https://github.com/doowb)\n* [twitter/doowb](http://twitter.com/doowb)\n\n### License\n\nCopyright © 2016, [Brian Woodward](https://github.com/doowb).\nReleased under the [MIT license](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on November 28, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Ffirebase-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Ffirebase-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Ffirebase-rpc/lists"}