{"id":18870352,"url":"https://github.com/streetstrider/run-or-attach","last_synced_at":"2026-02-14T17:30:14.565Z","repository":{"id":143907181,"uuid":"45738481","full_name":"StreetStrider/run-or-attach","owner":"StreetStrider","description":"kickstart Node.js daemon on first demand and attach to it","archived":false,"fork":false,"pushed_at":"2017-11-16T13:25:55.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T23:14:37.743Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StreetStrider.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2015-11-07T13:55:53.000Z","updated_at":"2017-11-15T17:33:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"01b455ec-2639-418a-b015-fc594607b708","html_url":"https://github.com/StreetStrider/run-or-attach","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frun-or-attach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frun-or-attach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frun-or-attach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Frun-or-attach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StreetStrider","download_url":"https://codeload.github.com/StreetStrider/run-or-attach/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239816505,"owners_count":19701753,"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-08T05:19:50.683Z","updated_at":"2026-02-14T17:30:14.507Z","avatar_url":"https://github.com/StreetStrider.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# run-or-attach\n\n\u003e kickstart Node.js daemon on first demand and attach to it\n\nSplit your application or utility into cli-part and daemon-part. Then connect to daemon in cli-part. Daemon will be started on first demand.\n\n```js\n/* main file */\nvar attach = require('run-or-attach')\n\nattach('/tmp/sock', require.resolve('./path-to-worker'))\n.then(function (flow)\n{\n\t/* flow is a function for pushing JSON to daemon */\n\tflow({ x: Math.random() })\n\n\t/* flow.recv is for receiving JSON answers from daemon */\n\tflow.recv = function (r)\n\t{\n\t\tconsole.dir(r)\n\t}\n\n\tflow.request({ x: 2 })\n\t.then(function (r)\n\t{\n\t\tconsole.info('request:')\n\t\tconsole.dir(r)\n\t})\n})\n```\n\n```js\n/* worker file */\nvar Worker = require('run-or-attach/worker')\n\nvar worker = Worker()\n\n/* recv is for handling incoming messages/requests */\nworker.recv = function (data)\n{\n\tdata.x += 1\n\n\t// answers can be sync or async\n\t// return falsy value to answer nothing\n\treturn new Promise((rs) =\u003e { setTimeout(() =\u003e rs(data), 100) })\n}\n\nworker.conn = function (flow)\n{\n\t// push realtime to client without waiting for request\n\tvar next = 0\n\tsetInterval(() =\u003e { next = next + 1; flow({ realtime: next }) }, 1000)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetstrider%2Frun-or-attach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreetstrider%2Frun-or-attach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetstrider%2Frun-or-attach/lists"}