马特宏峰的深度—项目方面的解释

Recently, I published an article on my new project, Matterhorn ?, a Node.js API server boilerplate. It provides a set of opinionated configuration files and some basic example code. These help developers get up and running faster with Node.js and TypeScript.

最近,我在我的新项目Matterhorn?上发表了一篇文章 ,这是一个Node.js API服务器样板。 它提供了一套实用的配置文件和一些基本的示例代码。 这些帮助开发人员使用Node.js和TypeScript更快地启动并运行。

Matterhorn is inspired by projects like Create React App and Gatsby CLI. The project's goal is to eliminate the barrier of entry required to use programming tools such as type systems, testing and linting frameworks, and even basic continuous integration.

马特宏峰的灵感来自于Create React App和Gatsby CLI等项目。 该项目的目标是消除使用编程工具(如类型系统,测试和整理框架,甚至基本的持续集成)所需的入门障碍。

This blog post will review each of the core aspects in Matterhorn. I will discuss details and the opinionated decision behind the framework of choice.

这篇博客文章将回顾马特宏峰的每个核心方面。 我将讨论选择框架背后的细节和明智的决定。

运行时和类型系统 (Runtime & Type System)

The core of this project is built with Node.js, a JavaScript runtime built on Chrome’s V8 JavaScript engine. It is recommended you use the latest stable version of Node.js to run this project. At the time of writing this post, it is 11.7.0.

该项目的核心是使用Node.js构建的,Node.js是基于Chrome的V8 JavaScript引擎构建JavaScript运行时。 建议您使用最新的稳定版Node.js来运行此项目。 在撰写本文时,它是11.7.0

Node.js is driven by a non-blocking event loop which makes it a great choice for building scalable network applications. For more information on Node.js check out their website.

Node.js由非阻塞事件循环驱动,这使其成为构建可伸缩网络应用程序的理想选择。 有关Node.js的更多信息,请访问其网站

Many Node.js projects are written in JavaScript. However, TypeScript, a type system for JavaScript, has witnessed a spike in attention at the end of 2018. Many developers are interested in learning TypeScript in 2019. Its adoption in open source JavaScript projects is increasing. The original purpose for Matterhorn was to jump start developers interested in building backend Node.js applications with TypeScript. As such, Matterhorn itself is written in TypeScript.

许多Node.js项目都是用JavaScript编写的。 但是,用于JavaScript的类型系统TypeScript在2018年底引起了人们的关注。许多开发人员都对2019年学习TypeScript感兴趣,它在开源JavaScript项目中的采用率正在上升。 Matterhorn的最初目的是激发对使用TypeScript构建后端Node.js应用程序感兴趣的开发人员。 因此,马塔角本身就是用TypeScript编写的。

As a type system, TypeScript is very comprehensive. While it may have a steep learning curve at first, the benefits from using it are paramount. It helps you, the developer, write cleaner, less buggy code. And once you’re familiar with the ecosystem and configuration process, you’ll be writing new features faster than you would with native JavaScript. Editors such as VSCode have TypeScript enabled by default. It provides an extensive set of developer tooling to further improve the developer experience.

作为类型系统,TypeScript非常全面。 虽然一开始它可能会有陡峭的学习曲线,但使用它的好处至关重要。 它可以帮助您(开发人员)编写更整洁,错误更少的代码。 并且,一旦您熟悉了生态系统和配置过程,就可以比使用本机JavaScript更快地编写新功能。 VSCode等编辑器默认情况下启用TypeScript。 它提供了广泛的开发人员工具集,以进一步改善开发人员体验。

API框架 (API Framework)

While it is possible to write an HTTP API using just Node.js, if a developer wants to achieve ecosystem maintainability, security, and scalability, they should use an API framework. When it comes to Node.js API frameworks, there are many to chose from such as Express, Koa, and Hapi. But there is one framework faster and more resilient than all the rest: Fastify.

尽管可以仅使用Node.js编写HTTP API,但是如果开发人员想要实现生态系统的可维护性,安全性和可伸缩性,则他们应该使用API​​框架。 对于Node.js API框架,有很多选择,例如Express,Koa和Hapi。 但是有一个框架比其他所有框架更快,更灵活Fastify

Fastify is a fast and low overhead web framework, for Node.js. It is inspired by Hapi and Express and operates on a plugin based architecture. It has a very healthy open source community, and over 90 public plugins from authentication to database bindings and everything in between. Additionally, Fastify maintains its own set of TypeScript bindings that are shipped with the module directly from NPM.

Fastify是一个用于Node.js的快速,低开销的Web框架。 它受Hapi和Express启发,并在基于插件的体系结构上运行。 它有一个非常健康的开源社区,并且有90多个公共插件,从身份验证到数据库绑定,以及介于两者之间的所有内容。 此外,Fastify维护其自己的TypeScript绑定集,该绑定集随NPM直接随模块一起提供。

测试赛跑者和林特 (Test Runner and Linter)

Backing up your code with unit tests is a standard in today’s programming ecosystem. Matterhorn comes with Jest, a popular JavaScript test runner. It is configured to work with TypeScript and even contains some examples for testing your Fastify API. Take note of Fastify’s inject method; it is very useful for testing your routes behavior.

使用单元测试备份代码是当今编程生态系统中的标准。 Matterhorn附带了流行JavaScript测试运行程序Jest。 它被配置为与TypeScript一起使用,甚至包含一些示例来测试Fastify API。 注意Fastify的inject方法; 这对于测试您的路线行为非常有用。

In addition to running tests, Jest is also configured to output code coverage documents. While code coverage is not the most important metric to consider when writing unit tests, it is valuable and can assist you in verifying you’re at least covering as much of your code base as possible.

除了运行测试外,Jest还配置为输出代码覆盖率文档。 尽管代码覆盖率并不是编写单元测试时要考虑的最重要指标,但它很有价值,可以帮助您验证至少覆盖了尽可能多的代码库。

In the open source community, code linters are a popular choice for enforcing a certain style of programming. They negate the need for stylistic code reviews. They can help developers catch errors in their code before they run it.

在开源社区中,代码特技是执行某种编程风格的流行选择。 它们消除了对样式代码审查的需要。 它们可以帮助开发人员在运行代码之前发现其错误。

Matterhorn is equipped with ESLint, a popular choice for JavaScript linting. The project was originally shipped with TSLint. However, this was swapped out in favor of ESLint because TypeScript officially announced plans to directly support the ESLint project. The linter is configured to suit the project maintainers opinions. It can easily be reconfigured for your own stylistic guidelines.

Matterhorn配备了ESLint,这是JavaScript衬里的流行选择。 该项目最初与TSLint一起提供。 但是,由于TypeScript 正式宣布了直接支持ESLint项目的计划,因此换成了ESLint。 短绒棉被配置为适合项目维护者的意见。 可以根据您自己的风格准则轻松对其进行重新配置。

持续集成 (Continuous Integration)

The final aspect of Matterhorn is the inclusion of a fully configured continuous integration pipeline. For many developers, especially those learning or just tinkering, this feature may not have much use. However, for those trying to develop a complete application and want the stability of enterprise development, this CI is for them.

马特洪峰的最后一个方面是包含一个完整配置的连续集成管道。 对于许多开发人员,尤其是那些正在学习或只是修修补补的开发人员,此功能可能用处不大。 但是,对于那些试图开发完整应用程序并希望稳定企业发展的人员而言,此CI适用于他们。

The pipeline is built on Azure DevOps (previously named Visual Studio Team Services). Azure DevOps is free for public repositories, and the pipeline utilities are extensive. It can be configured programmatically (Matterhorn) or through a visual editor (in a browser). You can check out Matterhorn’s CI pipeline here. It automatically builds for pull request updates and any new commits on master.

管道基于Azure DevOps(以前称为Visual Studio Team Services)构建。 Azure DevOps对于公共存储库是免费的,并且管道实用程序非常广泛。 可以以编程方式( Matterhorn )或通过可视化编辑器(在浏览器中)进行配置。 您可以在此处查看Matterhorn的CI管道。 它会自动构建用于请求更新和master上的任何新提交。

结论 (Conclusion)

Thank you for taking the time to read about the various aspects of Matterhorn. A lot went into consideration when picking services and utility modules for this project. The project is open source, and there is plenty of room for improvement so if you’d like to contribute check it out below.

感谢您抽出宝贵的时间来了解马特宏峰的各个方面。 在为该项目选择服务和实用程序模块时,需要考虑很多因素。 该项目是开源的,还有很多改进的余地,因此,如果您想在下面提供帮助,请查看。

Ethan-Arrowood/matterhornAn API boilerplate project built on Node.js and TypeScript ? - Ethan-Arrowood/matterhorngithub.com

Ethan-Arrowood / matterhorn 基于Node.js和TypeScript构建的API样板项目? -Ethan-Arrowood / matterhorng ithub.com

翻译自: https://www.freecodecamp.org/news/matterhorn-in-depth-project-aspects-explained-3348f569f30a/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值