Gathering detailed insights and metrics for egg-core
Gathering detailed insights and metrics for egg-core
Gathering detailed insights and metrics for egg-core
Gathering detailed insights and metrics for egg-core
npm install egg-core
Typescript
Module System
Min. Node Version
Node Version
NPM Version
90.6
Supply Chain
94
Quality
81.4
Maintenance
100
Vulnerability
100
License
TypeScript (99.62%)
JavaScript (0.3%)
Shell (0.08%)
Total Downloads
9,567,189
Last Day
2,440
Last Week
22,214
Last Month
97,784
Last Year
1,153,710
MIT License
221 Stars
382 Commits
92 Forks
35 Watchers
4 Branches
47 Contributors
Updated on Jun 09, 2025
Minified
Minified + Gzipped
Latest Version
5.5.1
Package Id
egg-core@5.5.1
Unpacked Size
107.69 kB
Size
29.33 kB
File Count
23
NPM Version
10.8.2
Node Version
20.18.1
Published on
Jan 22, 2025
Cumulative downloads
Total Downloads
Last Day
1.7%
2,440
Compared to previous day
Last Week
-0.2%
22,214
Compared to previous week
Last Month
-2.9%
97,784
Compared to previous month
Last Year
-2.8%
1,153,710
Compared to previous year
19
A core plugin framework based on @eggjs/koa. Support Commonjs and ESM both by tshy.
Don't use it directly, see egg.
Directory structure
1├── package.json 2├── app.ts (optional) 3├── agent.ts (optional) 4├── app 5| ├── router.ts 6│ ├── controller 7│ │ └── home.ts 8| ├── extend (optional) 9│ | ├── helper.ts (optional) 10│ | ├── filter.ts (optional) 11│ | ├── request.ts (optional) 12│ | ├── response.ts (optional) 13│ | ├── context.ts (optional) 14│ | ├── application.ts (optional) 15│ | └── agent.ts (optional) 16│ ├── service (optional) 17│ ├── middleware (optional) 18│ │ └── response_time.ts 19│ └── view (optional) 20| ├── layout.html 21│ └── home.html 22├── config 23| ├── config.default.ts 24│ ├── config.prod.ts 25| ├── config.test.ts (optional) 26| ├── config.local.ts (optional) 27| ├── config.unittest.ts (optional) 28│ └── plugin.ts
Then you can start with code below
1import { EggCore as Application } from '@eggjs/core'; 2 3const app = new Application({ 4 baseDir: '/path/to/app', 5}); 6app.ready(() => { 7 app.listen(3000); 8});
EggLoader can easily load files or directories in your egg project. In addition, you can customize the loader with low level APIs.
Load config/plugin.ts
Load config/config.ts and config/{serverEnv}.ts
If process.env.EGG_APP_CONFIG
is exists, then it will be parse and override config.
Load app/controller
Load app/middleware
Load app/extend/application.ts
Load app/extend/context.ts
Load app/extend/request.ts
Load app/extend/response.ts
Load app/extend/helper.ts
Load app.ts, if app.ts export boot class, then trigger configDidLoad
Load agent.ts, if agent.ts export boot class, then trigger configDidLoad
Load app/service
Retrieve application environment variable values via serverEnv
.
You can access directly by calling this.serverEnv
after instantiation.
serverEnv | description |
---|---|
default | default environment |
test | system integration testing environment |
prod | production environment |
local | local environment on your own computer |
unittest | unit test environment |
To get directories of the frameworks. A new framework is created by extending egg, then you can use this function to get all frameworks.
A loadUnit is a directory that can be loaded by EggLoader, cause it has the same structure.
This function will get add loadUnits follow the order:
loadUnit has a path and a type. Type must be one of those values: app, framework, plugin.
1{ 2 path: 'path/to/application', 3 type: 'app' 4}
To get application name from package.json
Get the infomation of the application
package.json
package.json
To load a single file. Note: The file must export as a function.
To load files from directory in the application.
Invoke this.loadToApp('$baseDir/app/controller', 'controller')
, then you can use it by app.controller
.
To load files from directory, and it will be bound the context.
1// define service in app/service/query.ts 2export default class Query { 3 constructor(ctx: Context) { 4 super(ctx); 5 // get the ctx 6 } 7 8 async get() {} 9} 10 11// use the service in app/controller/home.ts 12export default async (ctx: Context) => { 13 ctx.body = await ctx.service.query.get(); 14};
Loader app/extend/xx.ts to target, For example,
1await this.loadExtend('application', app);
| Param | Type | Description |
| ----------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |
| directory | String/Array
| directories to be loaded |
| target | Object
| attach the target object from loaded files |
| match | String/Array
| match the files when load, default to **/*.js
(if process.env.EGG*TYPESCRIPT was true, default to [ '\*\*/\_.(js | ts)', '!\*_/_.d.ts' ]
) |
| ignore | String/Array
| ignore the files when load |
| initializer | Function
| custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an options
object that contain path
|
| caseStyle | String/Function
| set property's case when converting a filepath to property list. |
| override | Boolean
| determine whether override the property when get the same name |
| call | Boolean
| determine whether invoke when exports is function |
| inject | Object
| an object that be the argument when invoke the function |
| filter | Function
| a function that filter the exports which can be loaded |
EggCore record boot progress with Timing
, include:
process.uptime
to record the script start running time, framework can implement a prestart file used with node --require
options to set process.scriptTime
)application start
or agent start
timerequire
durationStart record a item. If the item exits, end the old one and start a new one.
End a item.
Generate all record items to json
Please open an issue here.
Made with contributors-img.
No vulnerabilities found.
No security vulnerabilities found.