Original text: codesky. Me/archives/eg…

Published with nuggets although diverting but mainly! Now the exposure rate of sharing is too low!! So………………… Please click on the original blog collection and follow my weibo.

Why is the title of this article reversed?

It’s a personal experience. When I first saw Eggjs, IT was obvious that Egg was not my cup of coffee — I chose Koa because it was small and delicate, and all in Middleware. But isn’t EggJS gild the lily?

This new project uses a company-modified Version of the Egg that encapsulates several more services.

— I said no at first.

An egg and koa

From the perspective of development experience, THERE is a feeling of seeking common ground while reserving differences. Because KOA is found one by one, I seem to know why the world turns this way from zero, while the encapsulated world does not have such pleasure. Meanwhile, it expands some concepts: Service/Model/Middleware/Controller automatically registers, and in the koA world you might need to write your own code to do so.

Also, based on KOA, it is free from some of the selection difficulties, which means that you simply have to turn on its plugin and comply with egg’s rules.

, of course, this time also brought another kind of struggle, the framework of this kind of enterprise development rules of the development of a kind of standard grammar and specification, you can’t according to the way that oneself like, can only abide by the provisions of the it, no koa sense of freedom that kind of love how to write how to write, but from another perspective, possibly to the feasibility of the long-term maintenance of sacrifice.

configuration

It is similar to our usual configuration library, which is based on the env file name. It is worth mentioning that during unittest, the environment variable is changed to unittest, so you can customize the configuration of the test environment. If the configuration is not found, it is degraded to config.default.js.

test

If this article were simply an official document compressed and fed to you, you would not be happy reading it. The main thing I want to talk about is the convenience egg brings to our testing process.

When TESTING, I often think about the following questions: what to test, what to mock, and what library to choose. These three questions tend to get in the way, especially when there are too many mock steps — should SSO mock or not, should certain services mock or not. Mock or not to invoke other external services. You might not want to test it once you’re there.

You can mock the properties of a Service or context encapsulated in an egg, which makes the whole process very smooth. Another reason for this is that you don’t have to think about what library to use today.

The document

The remaining documents are koA and Egg. Koa has few concepts and basically looks up what is used, while Egg introduces more new concepts and built-in APIS. According to our urine nature, if you don’t read the long words, you may miss something. Some of the parts I missed have been drawn out here (escape).

When reading the Egg API document, remember that if it says the same as or alias, go to the specified location to view the interface information; Clicking on the source code can also be a bonus.

In a word

If you want to be regulated, egg is a good framework to use. You can also customize your own version of egg to encapsulate some of the most common services for your own use, but on the other hand, I have encountered too many of these: The problem with this deepening is that there is a Bug. If it is not you — who should blame it next?

Overall, while there was some pain, it wasn’t too bad to watch, but some of the scenes were great.