All Projects โ†’ eggjs โ†’ Egg Core

eggjs / Egg Core

Licence: mit
A core Pluggable framework based on koa.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Egg Core

Egg
๐Ÿฅš Born to build better enterprise frameworks and apps with Node.js & Koa
Stars: โœญ 17,616 (+8980.41%)
Mutual labels:  framework, koa, koa2, egg
Cool Admin Api
cool-admin-api ๆ˜ฏๅŸบไบŽegg.jsใ€typeormใ€jwt็ญ‰ๅฐ่ฃ…็š„apiๅผ€ๅ‘่„šๆ‰‹ๆžถใ€ๅฟซ้€Ÿๅผ€ๅ‘apiๆŽฅๅฃ
Stars: โœญ 188 (-3.09%)
Mutual labels:  koa, koa2, egg
Koa Proxies
a [emailย protected] proxy middleware
Stars: โœญ 125 (-35.57%)
Mutual labels:  koa, koa2
Tsed
๐Ÿ“ Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: โœญ 1,941 (+900.52%)
Mutual labels:  koa, nodejs-framework
Grial
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: โœญ 194 (+0%)
Mutual labels:  framework, nodejs-framework
Postgraphile
GraphQL is a new way of communicating with your server. It eliminates the problems of over- and under-fetching, incorporates strong data types, has built-in introspection, documentation and deprecation capabilities, and is implemented in many programming languages. This all leads to gloriously low-latency user experiences, better developer experiences, and much increased productivity. Because of all this, GraphQL is typically used as a replacement for (or companion to) RESTful API services.
Stars: โœญ 10,967 (+5553.09%)
Mutual labels:  koa, koa2
Koalerplate
Simple Koa Boilerplate for APIs
Stars: โœญ 118 (-39.18%)
Mutual labels:  koa, koa2
Sactive Web
๐Ÿš€ A dependency injection web framework for Node.js.
Stars: โœญ 143 (-26.29%)
Mutual labels:  koa, koa2
Chatroom
vue2่Šๅคฉๅฎค๏ผŒๅ›พ็ตๆœบๅ™จไบบ๏ผŒnode็ˆฌ่™ซ
Stars: โœญ 103 (-46.91%)
Mutual labels:  koa, koa2
Nobita
Nobita ๆ˜ฏไธ€ไธชๅŸบไบŽKoa่€Œ่ฏž็”Ÿ็š„ไธ€ๆฌพๆก†ๆžถใ€‚
Stars: โœญ 152 (-21.65%)
Mutual labels:  framework, koa2
Koa Hbs
Handlebars templates for Koa.js
Stars: โœญ 156 (-19.59%)
Mutual labels:  koa, koa2
Nest
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications on top of TypeScript & JavaScript (ES6, ES7, ES8) ๐Ÿš€
Stars: โœญ 42,981 (+22055.15%)
Mutual labels:  framework, nodejs-framework
Strapi
๐Ÿš€ Open source Node.js Headless CMS to easily build customisable APIs
Stars: โœญ 41,786 (+21439.18%)
Mutual labels:  koa, koa2
Kepler
The open source full-stack geosocial network platform
Stars: โœญ 125 (-35.57%)
Mutual labels:  framework, nodejs-framework
Core
๐Ÿš€ The Node.js Framework highly focused on developer ergonomics, stability and confidence
Stars: โœญ 11,697 (+5929.38%)
Mutual labels:  framework, nodejs-framework
Burnjs
A framework base on koa with typescript
Stars: โœญ 137 (-29.38%)
Mutual labels:  framework, koa
Lad
๐Ÿ‘ฆ Lad is the best Node.js framework. Made by a former Express TC and Koa team member.
Stars: โœญ 2,112 (+988.66%)
Mutual labels:  framework, koa
Koa Sslify
Enforce HTTPS in node.js koa apps
Stars: โœญ 100 (-48.45%)
Mutual labels:  koa, koa2
Koa Mobx React Starter
A straightforward starter for Node javascript web projects. Using Koa, MobX and ReactJS (with universal / isomorphic server rendering)
Stars: โœญ 102 (-47.42%)
Mutual labels:  koa, koa2
Vue Webpack Config
Koa2ใ€Webpackใ€Vueใ€Reactใ€Node
Stars: โœญ 151 (-22.16%)
Mutual labels:  koa, koa2

egg-core

NPM version build status Test coverage David deps Known Vulnerabilities npm download

A core Pluggable framework based on koa.

Don't use it directly, see egg.

Usage

Directory structure

โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ app.js (optional)
โ”œโ”€โ”€ agent.js (optional)
โ”œโ”€โ”€ app
|   โ”œโ”€โ”€ router.js
โ”‚   โ”œโ”€โ”€ controller
โ”‚   โ”‚   โ””โ”€โ”€ home.js
|   โ”œโ”€โ”€ extend (optional)
โ”‚   |   โ”œโ”€โ”€ helper.js (optional)
โ”‚   |   โ”œโ”€โ”€ filter.js (optional)
โ”‚   |   โ”œโ”€โ”€ request.js (optional)
โ”‚   |   โ”œโ”€โ”€ response.js (optional)
โ”‚   |   โ”œโ”€โ”€ context.js (optional)
โ”‚   |   โ”œโ”€โ”€ application.js (optional)
โ”‚   |   โ””โ”€โ”€ agent.js (optional)
โ”‚   โ”œโ”€โ”€ service (optional)
โ”‚   โ”œโ”€โ”€ middleware (optional)
โ”‚   โ”‚   โ””โ”€โ”€ response_time.js
โ”‚   โ””โ”€โ”€ view (optional)
|       โ”œโ”€โ”€ layout.html
โ”‚       โ””โ”€โ”€ home.html
โ”œโ”€โ”€ config
|   โ”œโ”€โ”€ config.default.js
โ”‚   โ”œโ”€โ”€ config.prod.js
|   โ”œโ”€โ”€ config.test.js (optional)
|   โ”œโ”€โ”€ config.local.js (optional)
|   โ”œโ”€โ”€ config.unittest.js (optional)
โ”‚   โ””โ”€โ”€ plugin.js

Then you can start with code below

const Application = require('egg-core').EggCore;
const app = new Application({
  baseDir: '/path/to/app'
});
app.ready(() => app.listen(3000));

EggLoader

EggLoader can easily load files or directories in your egg project. In addition, you can customize the loader with low level APIs.

constructor

  • {String} baseDir - current directory of application
  • {Object} app - instance of egg application
  • {Object} plugins - merge plugins for test
  • {Logger} logger - logger instance๏ผŒdefault is console

High Level APIs

loadPlugin

Load config/plugin.js

loadConfig

Load config/config.js and config/{serverEnv}.js

If process.env.EGG_APP_CONFIG is exists, then it will be parse and override config.

loadController

Load app/controller

loadMiddleware

Load app/middleware

loadApplicationExtend

Load app/extend/application.js

loadContextExtend

Load app/extend/context.js

loadRequestExtend

Load app/extend/request.js

loadResponseExtend

Load app/extend/response.js

loadHelperExtend

Load app/extend/helper.js

loadCustomApp

Load app.js, if app.js export boot class, then trigger configDidLoad

loadCustomAgent

Load agent.js, if agent.js export boot class, then trigger configDidLoad

loadService

Load app/service

Low Level APIs

getServerEnv()

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

getEggPaths()

To get directories of the frameworks. A new framework is created by extending egg, then you can use this function to get all frameworks.

getLoadUnits()

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:

  1. plugin
  2. framework
  3. app

loadUnit has a path and a type. Type must be one of those values: app, framework, plugin.

{
  path: 'path/to/application',
  type: 'app'
}

getAppname()

To get application name from package.json

appInfo

Get the infomation of the application

  • pkg: package.json
  • name: the application name from package.json
  • baseDir: current directory of application
  • env: equals to serverEnv
  • HOME: home directory of the OS
  • root: baseDir when local and unittest, HOME when other environment

loadFile(filepath)

To load a single file. Note: The file must export as a function.

loadToApp(directory, property, LoaderOptions)

To load files from directory in the application.

Invoke this.loadToApp('$baseDir/app/controller', 'controller'), then you can use it by app.controller.

loadToContext(directory, property, LoaderOptions)

To load files from directory, and it will be bound the context.

// define service in app/service/query.js
module.exports = class Query {
  constructor(ctx) {
    // get the ctx
  }

  get() {}
};

// use the service in app/controller/home.js
module.exports = function*() {
  this.body = this.service.query.get();
};

loadExtend(name, target)

Loader app/extend/xx.js to target, For example,

this.loadExtend('application', app);

LoaderOptions

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
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

Timing

EggCore record boot progress with Timing, include:

  • Process start time
  • Script start time(node don't implement an interface like 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 time
  • Load duration
  • require duration

start

Start record a item. If the item exits, end the old one and start a new one.

  • {String} name - record item name
  • {Number} [start] - record item start time, default is Date.now()

end

End a item.

  • {String} name - end item name

toJSON

Generate all record items to json

  • {String} name - record item name
  • {Number} start - item start time
  • {Number} end - item end time
  • {Number} duration - item duration
  • {Number} pid - pid
  • {Number} index - item index

Questions & Suggestions

Please open an issue here.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].