{"id":19691940,"url":"https://github.com/yviscool/simple-egg","last_synced_at":"2026-06-09T18:31:53.282Z","repository":{"id":143935304,"uuid":"128486755","full_name":"yviscool/simple-egg","owner":"yviscool","description":"egg 的一个简单实现","archived":false,"fork":false,"pushed_at":"2018-04-08T06:03:00.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T11:41:49.450Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/yviscool.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":"2018-04-07T01:37:40.000Z","updated_at":"2018-04-08T06:03:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"67afff7a-e43b-451b-9e8f-1ebbdbb29e32","html_url":"https://github.com/yviscool/simple-egg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yviscool/simple-egg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yviscool%2Fsimple-egg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yviscool%2Fsimple-egg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yviscool%2Fsimple-egg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yviscool%2Fsimple-egg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yviscool","download_url":"https://codeload.github.com/yviscool/simple-egg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yviscool%2Fsimple-egg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34121021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"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":[],"created_at":"2024-11-11T19:11:52.943Z","updated_at":"2026-06-09T18:31:53.222Z","avatar_url":"https://github.com/yviscool.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-egg\negg 的一个简单实现\n\n### environment\n\nlinux npm \n\n\n目录如下\n\n```shell\n── egg-example\n   ├── app\n   │   ├── controller\n   │   │   └── news.js\n   │   ├── middleware\n   │   │   └── robot.js\n   │   ├── router.js\n   │   └── service\n   │       └── news.js\n   ├── app.js\n   ├── config\n   │   └── config.default.js\n   ├── node_modules\n   │   ├── .bin\n   │   │   └── egg-bin\n   │   └── egg\n   │       ├── egg.js\n   │       ├── egg_loader.js\n   │       └── package.json\n   └── package.json\n\n```\n### start\n\n```shell\ngit clone ..\ncd egg-example\n```\n然后把 node_modules/egg/package.json 剪切出来，不然 npm i 会把 egg 目录删除了，不知道为什么。。。\n```shell\nnpm i \n```\n把 package.json 放回去\n执行\n```shell\nnpm run dev\n```\n\n核心目录就在 node_modules 下面的 .bin 隐藏目录和 egg目录。\n\n可以看到三个主要文件 egg-bin, egg.js, egg_loder.js . 三个加起来 180 行代码。\n\n\n\n### 执行流程\n\n```javascript\n// egg-example/package.json\n{\n  \"name\": \"example\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"dev\": \"egg-bin dev\"\n  },\n  \"dependencies\": {\n    \"koa\": \"^2.5.0\",\n    \"koa-router\": \"^7.4.0\"\n  }\n}\n```\n\n由于`node_modules/.bin/`目录会在运行时加入系统的 PATH 变量，因此在运行 npm 时，就可以不带路径，直接通过命令来调用这些脚本。 所以我们可以直接 npm run dev.\n\n这里 npm run dev 会找到 .bin 目录下载的 egg-bin。 有了入口就可以看源码了。 ( window 下面不能运行，)。\n\n其中比较难的就是 controller 和 service 的 this 传递。只要记住这两个基本都是 app.context 就行。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyviscool%2Fsimple-egg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyviscool%2Fsimple-egg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyviscool%2Fsimple-egg/lists"}