{"id":20571945,"url":"https://github.com/chef-js/core","last_synced_at":"2025-04-14T17:07:40.582Z","repository":{"id":43207482,"uuid":"457923385","full_name":"chef-js/core","owner":"chef-js","description":"Internal Shared Functionalities for Command Line Interface Static Files Server written in TypeScript","archived":false,"fork":false,"pushed_at":"2024-09-05T14:10:36.000Z","size":446,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T17:07:35.412Z","etag":null,"topics":["cli","framework","javascript","nodejs","nodejs-server","npm","single-page-app","single-port","spa","typescript"],"latest_commit_sha":null,"homepage":"https://chef-js.github.io/core/","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-10T19:43:21.000Z","updated_at":"2024-09-05T14:10:39.000Z","dependencies_parsed_at":"2024-09-19T07:55:17.172Z","dependency_job_id":"01b73a63-a790-40ca-b304-00bc3b84f8f3","html_url":"https://github.com/chef-js/core","commit_stats":{"total_commits":28,"total_committers":4,"mean_commits":7.0,"dds":0.2142857142857143,"last_synced_commit":"b640edc73aa0306f6b6be0009f0f69768fd29c80"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef-js%2Fcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chef-js","download_url":"https://codeload.github.com/chef-js/core/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923765,"owners_count":21183953,"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":["cli","framework","javascript","nodejs","nodejs-server","npm","single-page-app","single-port","spa","typescript"],"created_at":"2024-11-16T05:17:49.767Z","updated_at":"2025-04-14T17:07:40.558Z","avatar_url":"https://github.com/chef-js.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chef-core\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://badge.fury.io/js/chef-core.svg\" alt=\"npm package version\" /\u003e](https://badge.fury.io/js/chef-core) [\u003cimg src=\"https://circleci.com/gh/chef-js/core.svg?style=shield\" alt=\"tests status\" /\u003e](https://circleci.com/gh/chef-js/core) [\u003cimg src=\"https://img.shields.io/npm/dw/chef-core.svg?color=success\" alt=\"npm downloads per week\" /\u003e](https://www.npmts.com/package/chef-core)\n\n**chef-core** is a micro-service manager for web sockets and a static files server, designed for Node.js and written in TypeScript. It includes tests to ensure reliability.\n\nThis package is a core dependency used in three flavors:\n\n- [chef-express](https://npmjs.com/package/chef-express) an `express` web server with cache and fallback to index for 404s.\n- [chef-socket](https://npmjs.com/package/chef-socket) similar to `chef-express`, but with `socket.io` plugin capabilities on the same port.\n- [chef-uws](https://npmjs.com/package/chef-uws) similar to `chef-socket`, but uses `uWebSockets.js` instead of `express` and `socket.io`.\n\n## Minimal Chat Demo\n\nCheck out the minimal chat demo at https://chef-js-socket.herokuapp.com/\n\nTo set up the demo using `chef-socket`, run the following commands:\n\n```bash\n$ yarn add chef-socket\n$ yarn chef-socket node_modules/chef-socket/demo --plugin node_modules/chef-core/chat.js\n```\n\nAlternatively, for microWebSockets, see https://chef-js-uws.herokuapp.com/\n\nTo set up the demo using `chef-uws`, run the following commands:\n\n```bash\n$ yarn add chef-uws\n$ yarn chef-uws node_modules/chef-uws/demo --plugin node_modules/chef-core/chat.js\n```\n\n## API Documentation\n\nFor detailed API documentation, and types, refer to the [chef-core API](https://chef-js.github.io/core/)\n\n## Running\n\nThis library offers three different variants/flavors. Depending on the variant you need, refer to the relevant npm package's readme for instructions.\n\nTo get started with the basic usage, follow these steps:\n\n```bash\n# Serve 'dist' folder using express flavor on localhost:4200\n$ npx chef-express dist\n\n# Serve 'dist' folder using socket.io flavor on localhost:4200\n$ npx chef-socket dist\n\n# Serve 'dist' folder using uws flavor on localhost:4200\n$ npx chef-uws dist\n```\n\nTo serve the `dist` folder with express flavor on localhost:443, with development ssl, disabling cache:\n\n```bash\n$ npx chef-express dist --ssl --port 443 --maxCacheSize 0\n```\n\nTo serve the `dist` folder with socket flavor on localhost:4200, with a WebSocket plugin, in debug mode:\n\n```bash\n$ npx chef-socket dist --plugin ./path/to/plugin.js --debug\n```\n\n## Configuration\n\nYou can read the default configuration by using the following code:\n\n```ts\nconst config = require(\"chef-core/config\");\n```\n\nAlternatively, you can declare a custom configuration by omitting the defaults that don't suit your needs. Here's how the default config looks like:\n\n```ts\nconst { Config, getParams } = require(\"chef-core\");\n\nconst config: Config = {\n  // serve 404s as index.html\n  spa: true,\n  // folder to static serve files\n  folder: process.argv[2],\n  // max cache size prevents oom, set to 0 to disable cache\n  maxCacheSize: parseInt(getParam(\"maxCacheSize\", \"128\")),\n  // this enables http/ws logs\n  debug: process.argv.includes(\"--debug\"),\n  // ssl = undefined | { key, cert }\n  ssl: process.argv.includes(\"--ssl\") ? ssl : undefined,\n  // port on which the server listens\n  port: Number(getParam(\"port\", process.env.PORT || \"4200\")),\n  // typeof Record\u003cstring, Plugin\u003e, for cli use --plugin ./plugin.js any x of times\n  plugins: {},\n  // handshake event\n  join: getParam(\"join\", \"/join\"),\n  // disconnect from room event\n  leave: getParam(\"leave\", \"/leave\"),\n  // type of server to start\n  type: \"core\", // \"core\" | \"express\" | \"socket\" | \"uws\"\n};\n```\n\nYou can also check the resulting `server.config` after the server has started.\n\n## Plugins\n\nTo use plugins, you can import the `chef-socket` or `chef-uws` package and include the desired plugin. Here's an example:\n\n```ts\nconst chef = require(\"chef-socket\"); // or chef-uws\nconst chat = require(\"chef-core/chat\");\n\nchef({ plugins: { chat } }).then((server) =\u003e {\n  console.log(server.config);\n});\n```\n\n## Shim\n\nYou can use the `{ initialize, handshake }` format for plugins as well. Here's an example:\n\n```ts\nconst chef = require(\"chef-socket\"); // or chef-uws\nconst shim = require(\"chef-core/shim\");\n\nconst example = shim(\"example\", {\n  initialize: (io) =\u003e {\n    // initialize your game, this happens once\n    console.log(\"example plugin initialized\");\n  },\n  handshake: (socket) =\u003e {\n    // this happens once per socket, on connection\n    console.log(\"socket connected\");\n\n    socket.on(\"event\", ({ id, event, data }) =\u003e {\n      // do something with an event\n    });\n  },\n});\n\nchef({ plugins: { example } }).then((server) =\u003e {\n  console.log(server.config);\n});\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchef-js%2Fcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchef-js%2Fcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchef-js%2Fcore/lists"}