current position:Home>Egg enterprise framework - Installation

Egg enterprise framework - Installation

2021-08-27 08:59:17 iwhao_ top

This is my participation 8 The fourth of the yuegengwen challenge 23 God , Check out the activity details :8 Yuegengwen challenge

Design principles

We are well aware that enterprise application is pursuing standardization and co construction at the same time , You also need to think about how to balance the differences between different teams , Seek common ground while reserving differences . So we didn't choose the big bazaar model of the common framework of the community ( Integration is like a database 、 template engine 、 Front end framework and other functions ), It's about focusing on providing Web Development of core functions and a set of flexible and extensible plug-in mechanism . We don't make technology choices , Because fixed technology selection will make the scalability of the framework worse , Can't meet all kinds of customization needs . adopt Egg, The team's architects and technical leaders can easily build on their own technical architecture Egg On this basis, we expand the framework suitable for our own business scenarios .

Egg The plug-in mechanism of is highly extensible , A plug-in only does one thing ( such as Nunjucks The template encapsulates into egg-view-nunjucks、MySQL The database is encapsulated as egg-mysql).Egg Aggregate these plug-ins through the framework , And customize the configuration according to your own business scenarios , In this way, the development cost of the application becomes very low .

Egg Pursue 『 Convention over configuration 』, According to a set of unified agreement for application development , Adopting this approach within the team can reduce the learning costs of developers , Developers are no longer 『 A nail 』, It can flow . There is no agreed team , The cost of communication is very high , For example, some people will divide the stack by directory, while others will divide the function by directory , It's easy for developers to make mistakes if they don't have the same perception . But convention doesn't mean poor scalability , contrary Egg It's highly scalable , The framework can be customized according to the agreement of the team . Use Loader You can let the framework define the default configuration according to different environments , It can also cover Egg The default agreement of .

And express difference

Express yes Node.js A framework widely used by the community , Simple and extensible , Great for personal projects . But the framework itself lacks conventions , The standard MVC Models can be written in various ways .Egg Develop as agreed , Pursue 『 Convention over configuration 』, The cost of teamwork is low .

Sails Is and Egg The same is true 『 Convention over configuration 』 Framework , It's also very scalable . But compared to the Egg,Sails Support Blueprint REST API、WaterLine So scalable ORM、 Front end Integration 、WebSocket etc. , But these functions are all created by Sails Provided . and Egg No direct functionality , It's just the integration of various functional plug-ins , Such as the implementation egg-blueprint,egg-waterline And so on , Reuse sails-egg Framework integration of these plug-ins can replace Sails 了 .

Quick start

This article will be from the perspective of examples , Step by step, build a Egg.js application , Let you get started quickly Egg.js.

Environmental preparation

operating system : Support macOS,Linux,Windows Running environment : Suggested choice LTS edition , Minimum requirements 8.x. Quick initialization We recommend using scaffolding directly , Just a few simple instructions , You can quickly build projects (npm >=6.1.0):

$ mkdir egg-example && cd egg-example
$ npm init egg --type=simple
$ npm i
 Copy code 

Quick initialization

We recommend using scaffolding directly , Just a few simple instructions , You can quickly build projects (npm >=6.1.0):

$ mkdir egg-example && cd egg-example
$ npm init egg --type=simple
$ npm i
 Copy code 

Start project :

$ npm run dev
$ open http://localhost:7001
 Copy code 

characteristic

  • Offer based on Egg The ability to customize the upper framework
  • Highly extensible plug-in mechanism
  • Built in multi process management
  • be based on Koa Development , Excellent performance
  • The frame is stable , High test coverage
  • Progressive development

Directory structure

In the QuickStart , You should have a preliminary impression of the framework , Next, let's take a brief look at the directory convention specification .

egg-project
├── package.json
├── app.js ( Optional )
├── agent.js ( Optional )
├── app
|   ├── router.js
│   ├── controller
│   |   └── home.js
│   ├── service ( Optional )
│   |   └── user.js
│   ├── middleware ( Optional )
│   |   └── response_time.js
│   ├── schedule ( Optional )
│   |   └── my_task.js
│   ├── public ( Optional )
│   |   └── reset.css
│   ├── view ( Optional )
│   |   └── home.tpl
│   └── extend ( Optional )
│       ├── helper.js ( Optional )
│       ├── request.js ( Optional )
│       ├── response.js ( Optional )
│       ├── context.js ( Optional )
│       ├── application.js ( Optional )
│       └── agent.js ( Optional )
├── config
|   ├── plugin.js
|   ├── config.default.js
│   ├── config.prod.js
|   ├── config.test.js ( Optional )
|   ├── config.local.js ( Optional )
|   └── config.unittest.js ( Optional )
└── test
    ├── middleware
    |   └── response_time.test.js
    └── controller
        └── home.test.js
 Copy code 

The directory agreed by the framework :

  • app/router.js Used for configuration URL Routing rules , Specific see Router.
  • app/controller/** Used to parse user input , Return corresponding results after processing , Specific see Controller.
  • app/service/** For writing the business logic layer , Optional , It is recommended to use , Specific see Service.
  • app/middleware/** For writing middleware , Optional , Specific see Middleware.
  • app/public/** Used to place static resources , Optional , See the built-in plug-ins for details egg-static.
  • app/extend/** Extension for framework , Optional , See framework extension for details .
  • config/config.{env}.js For writing configuration files , See configuration for details .
  • config/plugin.js For configuring plug-ins that need to be loaded , See plug-ins for details .
  • test/** For unit testing , See unit test for details .
  • app.js and agent.js Used to customize initialization at startup , Optional , Please refer to start customization for details . About agent.js For more information, see Agent Mechanism .

Directory contracted by built-in plug-ins :

  • app/public/** Used to place static resources , Optional , See the built-in plug-ins for details egg-static.
  • app/schedule/** For timed tasks , Optional , See timing task for details .

To customize your own directory specification , See Loader API

  • app/view/** Used to place template files , Optional , Agreed by the template plug-in , See template rendering for details .
  • app/model/** For placing domain models , Optional , Agreed by domain class related plug-ins , Such as egg-sequelize.

That's all the content of this article , Thank you very much for seeing here , If this article is well written or a little helpful to you , Please thumb up , Please pay attention to , Please share , Of course, any questions can be discussed in the comments , I will answer positively , Thank you again for

copyright notice
author[iwhao_ top],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210827085915256l.html

Random recommended