{"id":19112380,"url":"https://github.com/actionhero/actionhero-node-client","last_synced_at":"2025-04-09T19:17:25.638Z","repository":{"id":3558083,"uuid":"4619374","full_name":"actionhero/actionhero-node-client","owner":"actionhero","description":"actionhero client (for other node servers)","archived":false,"fork":false,"pushed_at":"2025-04-01T15:51:40.000Z","size":1170,"stargazers_count":34,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-01T16:53:06.538Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/actionhero.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-06-10T23:40:36.000Z","updated_at":"2025-04-01T15:51:43.000Z","dependencies_parsed_at":"2023-12-01T20:31:11.088Z","dependency_job_id":"1043557f-4907-4265-bee5-b8f7330305e9","html_url":"https://github.com/actionhero/actionhero-node-client","commit_stats":{"total_commits":241,"total_committers":16,"mean_commits":15.0625,"dds":0.4522821576763485,"last_synced_commit":"8063749dac44360b925286f2d35c00c2923bc856"},"previous_names":["actionhero/actionhero-client"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionhero%2Factionhero-node-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionhero%2Factionhero-node-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionhero%2Factionhero-node-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionhero%2Factionhero-node-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/actionhero","download_url":"https://codeload.github.com/actionhero/actionhero-node-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415783,"owners_count":20935383,"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-11-09T04:32:54.743Z","updated_at":"2025-04-09T19:17:25.613Z","avatar_url":"https://github.com/actionhero.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActionheroNodeClient\nFor one node.js servers talking to another ActionHero server, over the socket protocol.\n\n![NPM Version](https://img.shields.io/npm/v/actionhero-node-client.svg?style=flat) ![Node Version](https://img.shields.io/node/v/actionhero-node-client.svg?style=flat) [![Greenkeeper badge](https://badges.greenkeeper.io/actionhero/actionhero-node-client.svg)](https://greenkeeper.io/) [![test](https://github.com/actionhero/actionhero-node-client/actions/workflows/test.yml/badge.svg)](https://github.com/actionhero/actionhero-node-client/actions/workflows/test.yml)\n\nThis library makes it easy for one nodeJS process to talk to a remote [actionhero](https://www.actionherojs.com/) server.\n\nThis library makes use of actionhero's TCP socket connections to enable fast, stateful connections.  This library also allows for many concurrent and asynchronous requests to be running in parallel by making use of actionhero's message counter.\n\n**notes:**\n* This Library is a server-server communication library, and is NOT the same as the websocket client library that is generated via the actionhero server.\n* Node.js v8+ is required to use this package, as it uses `async/await`.\n\n## Setup\n\nInstallation should be as simple as:\n\n```javascript\nnpm install --save actionhero-node-client\n```\n\nand then you can include it in your projects with:\n\n```javascript\nvar ActionheroNodeClient = require(\"actionhero-node-client\");\nvar client = new ActionheroNodeClient();\n```\n\nOnce you have included the ActionheroClient library within your project, you can connect like this:\n\n```javascript\nawait client.connect({\n  host: \"127.0.0.1\",\n  port: \"5000\",\n});\n```\n\ndefault options (which you can override) are:\n\n```javascript\nvar defaults = {\n  host: \"127.0.0.1\",\n  port: \"5000\",\n  delimiter: \"\\r\\n\",\n  logLength: 100,\n  secure: false,\n  timeout: 5000,\n  reconnectTimeout: 1000,\n  reconnectAttempts: 10,\n};\n```\n## Methods\n\nOne you are connected (by waiting for the \"connected\" event or using the `connect` callback), the following methods will be available to you:\n\n* `await ActionheroNodeClient.connect()`\n* `await ActionheroNodeClient.disconnect()`\n* `{error, data, delta} = await ActionheroNodeClient.paramAdd(key, value)`\n  * remember that both key and value must pass JSON.stringify\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.paramDelete(key)`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.paramsDelete()`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.paramView(key)`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.paramsView()`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.details()`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.roomView(room)`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.roomAdd(room)`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.roomLeave(room)`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `{error, data, delta} = await ActionheroNodeClient.say(room, msg)`\n  * `msg` can be a string or an Object\n* {error, data, delta} = await `ActionheroNodeClient.action(action)`\n  * this action method will not set or unset any params, and use those already set by `paramAdd`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n* `ActionheroNodeClient.actionWithParams(action, param)`\n  * this action will ignore any previously set params to the connection\n  * params is a hash of this form `{key: \"myKey\", value: \"myValue\"}`\n  * The return value will contain the response from the server (`data`), a possible error (`error`), and the response's duration (`delta`)\n\n## Events\n\nActionheroNodeClient will emit a few types of events (many of which are caught in the example below).  Here are the events, and how you might catch them:\n\n* `client.on(\"connected\")`\n* `client.on(\"end\")`\n* `client.on(\"welcome\", (welcomeMessage) =\u003e {})`\n  * welcomeMessage is a string\n* `client.on(\"error\", (error) =\u003e {})`\n  * errorMessage is a string\n  * This is only emitted for connection errors, not errors to your requests/actions\n* `client.on(\"say\", (message) =\u003e {})`\n  * message is a hash containing `timeStamp`, `room`, `from`, and `message`\n* `client.on(\"timeout\", (error, request, caller) =\u003e {})`\n  * request is the string sent to the api\n  * caller (the calling function) is also returned to with an error\n\n## Data\n\nThere are a few data elements you can inspect on `actionheroClient`:\n\n* `ActionheroNodeClient.lastLine`\n  * This is the last parsed JSON message received from the server (chronologically, not by messageID)\n* `ActionheroNodeClient.userMessages`\n  * a hash which contains the latest `say` message from all users\n* `ActionheroNodeClient.log`\n  * An array of the last n parsable JSON replies from the server\n  * each entry is of the form {data, timeStamp} where data was the server's full response\n* `ActionheroNodeClient.messageCount`\n  * An integer counting the number of messages received from the server\n\n## Example\n\n```javascript\nvar ActionheroNodeClient = require(\"actionhero-node-client\");\n\nasync function main () {\n  const client = new ActionheroNodeClient()\n\n  client.on('say', (message) =\u003e {\n    console.log(' \u003e SAY: ' + message.message + ' | from: ' + message.from)\n  })\n\n  client.on('welcome', (welcome) =\u003e {\n    console.log('WELCOME: ' + welcome)\n  })\n\n  client.on('error', (error) =\u003e {\n    console.log('ERROR: ' + error)\n  })\n\n  client.on('end', () =\u003e {\n    console.log('Connection Ended')\n  })\n\n  client.on('timeout', (request, caller) =\u003e {\n    console.log(request + ' timed out')\n  })\n\n  await client.connect({host: '127.0.0.1', port: '5000'})\n\n  // get details about myself\n  console.log('My Details: ', client.details)\n\n  // try an action\n  const params = { key: 'mykey', value: 'myValue' }\n  let {error, data, delta} = await client.actionWithParams('cacheTest', params)\n  if (error) { throw error }\n  console.log('cacheTest action response: ', data)\n  console.log(' ~ request duration: ', delta)\n\n  // join a chat room and talk\n  await client.roomAdd('defaultRoom')\n  await client.say('defaultRoom', 'Hello from the actionheroClient')\n  await client.roomLeave('defaultRoom')\n\n  // leave\n  await client.disconnect()\n  console.log('all done!')\n}\n\nmain()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factionhero%2Factionhero-node-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factionhero%2Factionhero-node-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factionhero%2Factionhero-node-client/lists"}