{"id":16760509,"url":"https://github.com/bjoernricks/socketize","last_synced_at":"2026-05-18T18:40:02.125Z","repository":{"id":57365590,"uuid":"141603948","full_name":"bjoernricks/socketize","owner":"bjoernricks","description":"Promise based socket communication for Node.js","archived":false,"fork":false,"pushed_at":"2018-08-04T12:02:09.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T04:34:10.448Z","etag":null,"topics":["javascript","networking","nodejs","promise","socket"],"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/bjoernricks.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-07-19T16:15:29.000Z","updated_at":"2018-08-04T12:02:10.000Z","dependencies_parsed_at":"2022-08-23T20:10:45.771Z","dependency_job_id":null,"html_url":"https://github.com/bjoernricks/socketize","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/bjoernricks%2Fsocketize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernricks%2Fsocketize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernricks%2Fsocketize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoernricks%2Fsocketize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjoernricks","download_url":"https://codeload.github.com/bjoernricks/socketize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243801600,"owners_count":20350105,"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":["javascript","networking","nodejs","promise","socket"],"created_at":"2024-10-13T04:23:44.810Z","updated_at":"2026-05-18T18:39:57.101Z","avatar_url":"https://github.com/bjoernricks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# socketize\n\nPromise based socket communication for Node.js\n\n## The Problem\n\nNode.js provides a callback based Socket API in the\n[Net](https://nodejs.org/dist/latest-v8.x/docs/api/net.html#net_class_net_socket)\npackage. Using this API you might end up in the callback hell.\nTherefore **socketize** provides a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)\nbased Socket communication arround the Net API.\n\n## Installation\n\nTo install the stable version:\n\n```\nnpm install --save socketize\n```\n\nif you are using [npm](https://www.npmjs.com/) as your package manager and\n\n```\nyarn add socketize\n```\n\nfor using [yarn](https://yarnpkg.com/en/).\n\n## Examples\n\n### Simple Unix Socket communication\n\n```JavaScript\nimport Socket from 'socketize';\n\nconst socket = new Socket();\n\nsocket.connect({path: '/var/run/my.unix.socket'})\n  .then(() =\u003e socket.write('Hello world'));\n  .then(() =\u003e socket.read())\n  // remote server responds with '42'\n  .then(answer =\u003e console.log('The answer is', answer));\n  // 'The answer is 42'\n  .catch(err =\u003e console.log(err));\n```\n### Stateful reading\n\n```JavaScript\nimport Socket from 'socketize';\n\nconst createReader = () =\u003e {\n  const end = false;\n  return {\n    read: (data = '', chunk) =\u003e {\n      // read until 'END' is contained in the response\n      const readdata = data + chunk;\n      if (readdata.endsWith('END')) {\n        end = true;\n        return data += chunk.slice(0, -3).trim();\n      }\n      return readdata;\n    };\n    isDone: () =\u003e end,\n  };\n};\n\nconst reader = createReader();\nconst socket = new Socket();\n\nsocket.connect({path: '/var/run/my.unix.socket'})\n  .then(() =\u003e socket.write('Hello world'));\n  .then(() =\u003e socket.read(reader.read, reader.isDone));\n  // remote server responds with '42 END'\n  .then(answer =\u003e console.log('The answer is' answer));\n  // 'The answer is 42'\n```\n\n## License\n\nLicensed under the MIT License, Copyright © 2018 Björn Ricks\n\nSee [LICENSE](./LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjoernricks%2Fsocketize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjoernricks%2Fsocketize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjoernricks%2Fsocketize/lists"}