Node.JS的魔力与神话

In May 2020, Node.JS turned 11 years old.

2020年5月,Node.JS才11岁。

Since its inception, this programming language has brought the magic of asynchrony into JavaScript and gave us the ability to create applications with an unprecedented speed of request processing. And over all these years Node.JS has overgrown with many myths about its reliability and functionality.

自成立以来,这种编程语言就将异步的魔力带入了JavaScript,并使我们能够以前所未有的请求处理速度创建应用程序。 多年来,Node.JS在其可靠性和功能性方面已散布了许多神话。

I have known Node.JS since its first appearance, and we have been united by close cooperation for years. That is why I decided to write this article and share my own point of view regarding the magic and myths of Node.JS.

自从Node.JS首次出现以来,我就已经知道它了,多年来我们一直紧密合作。 这就是为什么我决定写这篇文章并就Node.JS的魔力和神话分享我自己的观点的原因。

Node.JS的魔力 (Magic of Node.JS)

Back in 2009, then unknown Ryan Dahl created Node.JS and gave the IT community a completely new way to build scalable network servers — simple, low-cost and fast.

早在2009年,当时不知名的Ryan Dahl创建了Node.JS,并为IT社区提供了一种全新的方式来构建可扩展的网络服务器-简单,低成本和快速。

Dahl created magic: he turned JavaScript from a highly-specialized into a general-purpose language. Node.js added the ability for JavaScript to interact with input/output devices through its API to connect other external libraries written in different languages, providing calls to them from JavaScript code.

达尔创造了魔力:他将JavaScript从高度专业化的语言变成了通用语言。 Node.js增加了JavaScript通过其API与输入/输出设备进行交互的功能,以连接以不同语言编写的其他外部库,从而从JavaScript代码提供对它们的调用。

However, the most important Dahl’s trick was event-oriented and asynchronous (or reactive) programming with non-blocking I/O.

但是,Dahl最重要的技巧是使用非阻塞I / O进行面向事件的异步(或React式)编程。

In the world before Node.JS, we worked with a multi-threaded server which used the thread-per-request model: the server can process several requests at the same time, but only one request per thread. What does it mean? Supposing, to process with N requests, the server needs N threads. If the server receives N + 1 requests, then it must wait until one of the threads becomes available.

在Node.JS之前的世界中,我们使用的是每线程请求模型的多线程服务器:该服务器可以同时处理多个请求,但每个线程只能处理一个请求。 这是什么意思? 假设要处理N个请求,服务器需要N个线程。 如果服务器收到N + 1个请求,则它必须等待直到其中一个线程可用。

Unlike a multi-threaded server, Node.js uses non-blocking I/O operations. It means that the mainstream will not be blocked by I/O operations, and the server will continue to serve requests, regardless of their number. It’s a kind of magic, isn’t it?

与多线程服务器不同,Node.js使用非阻塞I / O操作。 这意味着主流将不会被I / O操作阻塞,并且服务器将继续为请求提供服务,而不管它们的数量如何。 这是一种魔术,不是吗?

Image for post
Block diagram of NodeJs single-threaded event loop handling concurrent traffic.
NodeJ的单线程事件循环处理并发流量的框图。

Node.JS的胜利 (Triumph of Node.JS)

Triumph came to Node JS a couple of years after its first release.

在第一个发行版发布几年后,Triumph就加入了Node JS。

Worldwide technology pioneers such as LinkedIn, Uber and PayPal were among the first companies which decided to switch to Node.JS.

诸如LinkedIn,Uber和PayPal之类的全球技术先驱是决定改用Node.JS的首批公司之一。

Their results were exceptional: after updating the mobile application through Node.JS, LinkedIn and Uber reported the exponential increase in the effectiveness of communications with partners and customers.

他们的结果非常出色:通过Node.JS更新了移动应用程序之后,LinkedIn和Uber报告了与合作伙伴和客户的交流效率的指数级增长。

And here is the PayPal’s performance test comparison between Java and Node.JS below, which speaks for itself:

这是下面的Java与Node.JS之间的PayPal性能测试比较,这一点不言而喻:

Image for post
The PayPal’s performance test comparison between Java and Node.JS
PayPal在Java和Node.JS之间的性能测试比较

A 200ms reduction in page response time and a 90% increase in the number of requests that an application can execute per second — that is truly impressive.

页面响应时间减少了200ms,应用程序每秒可以执行的请求数量增加了90%,这确实令人印象深刻。

Node.JS的神话 (Myths of Node.JS)

Now then, let’s break free from the magical charm and take a look at another side of Node.JS.

现在,让我们摆脱魔术的魅力,看看Node.JS的另一面。

Having gone through the triumph stage, over the next few years Node.JS did not developed so actively, and one can say it has been in decline.

在经历了胜利的阶段之后,在接下来的几年中,Node.JS并没有那么活跃地发展,并且可以说它一直在下降。

That is why over the past 5 years Node.JS was overgrown with myths that prevent many developers from appreciating its current merits now.

这就是为什么在过去的5年中,Node.JS充斥着神话,使许多开发人员无法欣赏它目前的优点。

Well, I would like to dispel the main ones.

好吧,我想消除主要问题。

误区1。 Node.JS太原始了。 (Myth #1. Node.JS is too primitive.)

It is true, if you have not followed its updates since 2014.

的确如此,如果您自2014年以来没有关注它的更新。

As I was saying, having gotten all the best from JS at the start, Node.JS really slowed down in 2012–2014. “Zero” versions of this period did not please us with stability and functionality.

就像我说的那样,Node.JS从一开始就获得了JS的所有优点,但在2012-2014年间确实放慢了速度。 这个时期的“零”版本在稳定性和功能上并没有令我们满意。

In 2015 the situation changed dramatically: Node.JS released version 4.0 and forged ahead — this version not only supported all previously released JS libraries and frameworks, but also included all the latest technologies, which were developed on the io.js fork.

在2015年,情况发生了巨大变化:Node.JS发布了4.0版并向前发展-此版本不仅支持以前发布的所有JS库和框架,还包括所有在io.js分支上开发的最新技术。

Since 2015 and until now, we have seen a rapid improvement of Node.JS. The ability to create multithreaded parallel applications, implement parallel programming primitives and work with shared memory — this is a small part of what Node.JS gives us now.

从2015年至今,我们已经看到Node.JS的快速改进。 创建多线程并行应用程序,实现并行编程原语以及使用共享内存的能力-这只是Node.JS现在为我们提供的一小部分。

in addition, in April 2020 a new version of Node JS was released, and we still have to evaluate its merits.

此外,2020年4月发布了新版本的Node JS,我们仍然需要评估其优点。

I hope, these arguments are enough to move Node JS from “primitive” to “worth learning” category.

我希望这些论点足以将Node JS从“原始”类别转移到“值得学习”类别。

神话2。 Node.JS不适合开发对准确性和不间断操作有最高要求的应用程序。 (Myth #2. Node.JS is not suitable for developing applications with the highest requirements for accuracy and uninterrupted operation.)

I associate this myth with the fact that initially Node.JS did not have strict code standards. Certainly, if we do not have standards, it is pointless to talk about the reliability of Node.JS for these applications.

我把这个误解与最初Node.JS没有严格的代码标准这一事实联系在一起。 当然,如果我们没有标准,那么谈论Node.JS对于这些应用程序的可靠性毫无意义。

Should we be convinced that Node.JS is not suitable for serious projects after all? No, we shouldn’t.

我们是否应该说服Node.JS毕竟不适合大型项目? 不,我们不应该。

All we need to do is to choose the right standards and set up their compliance check.

我们需要做的就是选择正确的标准并设置其合规性检查。

Working with Node.JS on projects of Enterprise level we rely on solid code style standards, for example Airbnb provides a good JavaScript Style Guide. In order to make sure that the code meets the necessary requirements, we use TS Lint / ES Lint.

在企业级项目上使用Node.JS,我们依赖可靠的代码样式标准,例如Airbnb提供了很好JavaScript样式指南。 为了确保代码满足必要的要求,我们使用TS Lint / ES Lint。

The check runs before the committing phase, and all possible errors are corrected at the “zero” stage.And, of course, we do not forget about the good Unit and Integration test coverage at the final stages.This approach allows us to create applications with the highest requirements for accuracy and uninterrupted operation.

该检查在提交阶段之前进行,所有可能的错误都在“零”阶段得到纠正。当然,我们也不会忘记最后阶段良好的单元和集成测试覆盖率。这种方法使我们能够创建应用程序对准确性和不间断运行的最高要求。

Let’s consider that another myth is destroyed.

让我们考虑另一个神话被摧毁了。

误区3。 Node.JS存在类型安全问题。 (Myth #3. Node.JS has a type-safety problem.)

I heard this phrase from a few developers as the reason why they do not use Node.JS.

我从一些开发人员那里听到了这句话,这是他们不使用Node.JS的原因。

Here again, the question is how much you know about Node.JS and what technology stack you have in general.

同样,这里的问题是您对Node.JS了解多少,以及总体上拥有什么技术堆栈。

As for our team, we completely solved the type-safety problem using TypeScript config and setting automatic code checks.

对于我们的团队,我们使用TypeScript配置并设置自动代码检查完全解决了类型安全问题。

We have used this approach on many projects, and now I can say with confidence: with good automated code quality checks, the TypeScript guarantees the necessary level of a type safety.

我们已经在许多项目中使用了这种方法,现在我可以放心地说:通过良好的自动化代码质量检查,TypeScript保证了必要的类型安全性。

Instead of conclusion: as you already noticed, I like Node.JS. I am impressed by the improvement of this programming language, and I see its great potential in the future.

而不是结论:您已经注意到,我喜欢Node.JS。 这种编程语言的改进给我留下了深刻的印象,并且我看到了其未来的巨大潜力。

I am also convinced that Node.JS has a great deal of advantages in server-side development of solutions with different levels of complexity right now. It is not inferior to static languages, and in some cases even surpasses them, that it why it is definitely worth paying attention to.

我也坚信,Node.JS目前在服务器端开发具有不同复杂程度的解决方案方面具有许多优势。 它不亚于静态语言,并且在某些情况下甚至超过了它们,这就是为什么它绝对值得关注的原因。

翻译自: https://medium.com/swlh/magic-and-myths-of-node-js-aa89b21dd904

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值