{"id":15890331,"url":"https://github.com/chef-js/socket","last_synced_at":"2025-10-30T10:39:56.088Z","repository":{"id":57197713,"uuid":"457870895","full_name":"chef-js/socket","owner":"chef-js","description":"static files server designed for node written in typescript, with tests. with web-sockets micro-service manager, at the same port","archived":false,"fork":false,"pushed_at":"2025-05-24T21:13:59.000Z","size":1013,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-29T05:30:27.505Z","etag":null,"topics":["chat","chat-app","chat-application","cli","express","http-server","javascript","nodejs","nodejs-server","socket-io","typescript","websockets"],"latest_commit_sha":null,"homepage":"https://chef-js.github.io/socket/","language":"TypeScript","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/chef-js.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":"2022-02-10T17:03:04.000Z","updated_at":"2025-05-24T21:14:02.000Z","dependencies_parsed_at":"2024-06-08T03:29:06.742Z","dependency_job_id":"c8847f2c-bcb3-455c-8768-66c7da772f89","html_url":"https://github.com/chef-js/socket","commit_stats":{"total_commits":52,"total_committers":4,"mean_commits":13.0,"dds":0.09615384615384615,"last_synced_commit":"0908d42507071898d717c3700b0178cb86649a8f"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/chef-js/socket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fsocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fsocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fsocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fsocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chef-js","download_url":"https://codeload.github.com/chef-js/socket/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fsocket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281793494,"owners_count":26562612,"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","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["chat","chat-app","chat-application","cli","express","http-server","javascript","nodejs","nodejs-server","socket-io","typescript","websockets"],"created_at":"2024-10-06T07:05:15.018Z","updated_at":"2025-10-30T10:39:56.082Z","avatar_url":"https://github.com/chef-js.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chef-socket\n\n\u003cimg style=\"max-width: 100%; float: right;\" src=\"https://raw.githubusercontent.com/chef-js/core/main/chef.svg\" alt=\"kisscc0\" width=\"200\" height=\"200\" /\u003e\n\n[\u003cimg src=\"https://img.shields.io/npm/v/chef-socket?style=for-the-badge\u0026color=success\" alt=\"npm version\" /\u003e](https://www.npmjs.com/package/chef-socket?activeTab=versions)\n[\u003cimg src=\"https://img.shields.io/circleci/build/github/chef-js/socket/main?style=for-the-badge\" alt=\"build status\" /\u003e](https://app.circleci.com/pipelines/github/chef-js/socket)\n\n**static files server** designed for **node** written in **typescript**, with **tests**\n\nwith **web-sockets** micro-service manager, at the **same port**\n\n- `express` for routing\n- `socket.io` for websockets\n\n## Chat Demo\n\nhttps://chef-socket.pietal.dev/\n\n### Chat using CLI\n\n```bash\n$ yarn add chef-socket\n$ yarn chef-socket node_modules/chef-socket/demo --plugin node_modules/chef-socket/chat.js\n```\n\n### Chat using node.js\n\n```ts\nconst { cook, chat } = require(\"chef-socket\");\n\ncook({\n  folder: \"node_modules/chef-socket/demo\",\n  plugins: { chat },\n}).then((server) =\u003e {\n  console.log(server.config);\n});\n```\n\n## Serve folder CLI\n\n```bash\n$ npx chef-socket folder [--plugin node_modules/chef-socket/chat.js]\n```\n\n## Serve folder node.js\n\n```ts\nconst { cook } = require(\"chef-socket\");\n\ncook({ folder: \"folder\" }).then((server: Express.Application) =\u003e {\n  // server api is get, post, any\n  server.any(\"/*\", (req: Express.Request, res: Express.Response) =\u003e {\n    res.end(\"200 OK\");\n  });\n});\n```\n\n- minimal configuration is zero configuration, all values have defaults\n- if `folder` param is omitted default `index.html` is read from `folder = '.'`\n- serves from http://localhost:3000 unless `port` specified\n\n## Configuration\n\nFor more information about config parameters read:\n\n- The default configuration https://github.com/chef-js/core#configuration\n- The parameters types https://chef-js.github.io/core/types/Config.html\n\n## Plugins\n\nThe **plugins** are a mighty thing, think of them like **chat rooms**,\n\nafter a client **handshakes** the chat room, his messages start being **forwarded** to that room,\n\nand it is being handled there by the **room's own plugin**.\n\nThis means you can have for example: a **chat** server and other unrelated **websocket services**\n\nat the **same port** as the **files server** too. **One** client may be in **many** rooms.\n\n### STEP 1: Before Connection\n\n- client -\u003e `socket.io-client` connects to `location.origin.replace(/^http/, 'ws')`\n- server -\u003e waits for any incoming `config.join` events\n\n### STEP 2: Connection\n\n- client -\u003e sends `join` event with room name (topic/plugin name)\n- server -\u003e if such plugin is configured joins client to that plugin\n\n### STEP 3: After Connection\n\n- client -\u003e does some actions (emits, receives)\n- server -\u003e plugin responds to websocket actions\n\n### STEP 4: Finish Connection\n\n- client -\u003e disconnects after some time\n- server -\u003e broadcasts to all plugins from room that client left (`config.leave`)\n\n## API\n\n- a plugin is a function `(ws, { id, event, data })`\n- it is called **each time** the frontend websocket emits to server\n- you have to handle first join etc. yourself\n- context (`this`) of each plugin is the `server` instance.\n- plugins receive and send the events in the format of:\n\n```ts\ntype Event = {\n  id: string;      // socket gains unique id on connection\n  event: string;   // event name to send in frontend/receive in backend\n  data?: any;      // defaults to undefined, can be serializable primitive or JSON\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchef-js%2Fsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchef-js%2Fsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchef-js%2Fsocket/lists"}