This article will introduce the boot of Eggjs that is a Node.js web framework.
It is based on Koa and can satisfy your requirement through a large of plugins and middleware, even a your own framework. It is very important to create a cluster, an agent process and some worker processes when it is running. The cluster makes it stronger. Next, we can understand it by reading the source code.
Eggjs has a few major libs, egg-core、egg、egg-cluster、egg-bin、egg-scripts and so on.
egg-core: it extends Koa and is as a parent object of every agent and worker.
egg: it defines some actions for agent and worker, you can almost use these actions to create an app of a single process.
egg-cluster: it creates a cluster and manages them.
egg-scripts and Egg-bin: their job is run the whole app in a different environment.
Tips: We will discuss Eggjs with basing 2.x.x version.
如果不清楚什么是Egg.js,希望能移步到它的官网简单看下。另外说它是__约定大于配置__的话,我只能说你真的不了解它,或者说不了解框架,哪个框架没有约定?毕竟没有规矩不成方圆,何况是逻辑性的程序呢?官方列出的特性如下:
1.提供基于 Egg 定制上层框架 的能力
2.高度可扩展的插件机制
3.内置多进程管理
4.基于 Koa 开发,性能优异
5.框架稳定,测试覆盖率高
6.渐进式开发
第1条,它有那么Koa也有啊。第2条,它有,难道Koa、Express等就没有嘛?第4条,更好的补充了Koa不是更好吗?第5条,难道别的框架就不稳定了?第6条,前端鼓吹渐进式、后端也鼓吹,那究竟什么是渐进式呢?
在我看来最吸引我的是第3条,__内置多进程管理__,这个在其它主流nodejs框架中是稀缺的特性,此文就简单聊聊它。
前端代码运行在客户端的浏览器里,当客户端(浏览器)出现任何问题,在没有错误日志的情况下,我们都是不知道问题发生在哪,我们只能依靠猜测或者自己不断尝试才知道,或者永远不知道问题。
1.通过 window.onerror,可惜只能获得基础的 js 错误,Promise、async/await 里的错误无法捕获,它收到同源决策的影响
2.Promise 通过catch方法
3.async/await 通过 try - catch
4.Vue 可以通过全局 Vue.config.errorHandler 去获得非 Promise、async/await 里的错误,可以理解为 Vue 里的 window.onerror
Update your browser to view this website correctly. Update my browser now