by Dariya Kursova
通过达里娅·库尔索娃(Dariya Kursova)
JavaScript as programming language and data format (JSON) has changed web development drastically. Integrating Node.js with it to do things on the server as well as in browser is a trend lately. These two sentences, we feel, have to be illuminated and explained for everyone to grasp. So in this article, we are going to talk about why use Node.js, what is Node.js used for and top examples of Node.js in use.
JavaScript作为编程语言和数据格式(JSON)已大大改变了Web开发 。 将Node.js与之集成以在服务器上以及在浏览器中执行操作是最近的趋势。 我们认为,这两个句子必须加以阐明和解释,以供所有人理解。 这篇文章所以,我们要说说为什么使用Node.js的, 什么是用于和使用Node.js的顶部例子 Node.js的。
Surely, this is technological stuff for programmers/coders, and some might find the language not quite apprehendable. With this in mind, we will try to make it as light-some as possible and speak in more human terms. We just want to explain what makes Node.js great and what is all the hype about.
当然,对于程序员来说,这是技术性的东西,有些人可能会觉得这种语言不是很容易理解。 考虑到这一点,我们将尝试使其尽可能轻巧,并以更人性化的方式讲。 我们只想解释是什么使Node.js变得出色 ,以及所有的炒作。
First off, the praise is well deserved, as Node decisively eased the work of anyone building web applications. After decades of web request/response paradigm, having real-time 2-way communication is a bliss. That is a communication between the server and the client. And that, in turn, is a model to distribute workloads among service providers (server) and service requests (clients).
首先,赞美是当之无愧的,因为Node可以果断地简化任何构建Web应用程序的工作。 经过数十年的Web请求/响应范例, 实现实时2向通信是一种幸福。 那是服务器和客户端之间的通信。 反过来,这又是一种在服务提供商(服务器)和服务请求(客户端)之间分配工作负载的模型。
On board so far? Great, now some statistical info about the demand for Node.js. It is by far the fastest growing language in use, and it ranks in Top-10 most wanted developer skills. The use of Node.js is mainly for full stack, front-end, and back-end.
船上到目前为止? 太好了,现在有一些有关Node.js需求的统计信息。 它是目前使用中发展最快的语言,在十大最受欢迎的开发人员技能中排名第一。 Node.js的使用主要用于完整堆栈,前端和后端。
As we’ve previously touched on this in Best Node.js examples, Node.js is a JavaScript runtime environment. But what is that, one might ask. By run-time environment, the infrastructure to build and run software applications is meant. To build applications in JavaScript, in this case. Let’s see what are the Node.js definition versions.
正如我们之前在Best Node.js示例中谈到的那样, Node.js是一个JavaScript运行时环境 。 但这可能是一个问题。 在运行时环境中,意味着构建和运行软件应用程序的基础结构。 在这种情况下,要使用JavaScript构建应用程序。 让我们看看什么是Node.js定义版本。
The company itself describes Node.js as a “JavaScript runtime built on Chrome V8 engine”. Wikipedia states, that “Node.js is an open-source and cross-platform environment to execute code”. According to TechTarget, it is “a development platform aimed at building server-side applications”. And PCMag tells us that Node.js is “a platform with its own web server for better control”. That is certainly enough to grasp the main idea.
该公司本身将Node.js描述为“基于Chrome V8引擎构建JavaScript运行时”。 维基百科指出,“ Node.js是执行代码的开源和跨平台环境”。 根据TechTarget的说法,它是“旨在构建服务器端应用程序的开发平台”。 PCMag告诉我们,Node.js是“具有自己的Web服务器以更好地控制的平台”。 这当然足以掌握主要思想。
A brief summary would be as goes:
简要总结如下:
How does Node.js work? Taking a simple task of opening a file on a server, the sequence would be:
Node.js如何工作? 进行一个简单的在服务器上打开文件的任务,顺序为:
In other words, with Node.js you do not have to wait and can go on with next tasks. This is one of the reasons it is so efficient. Now, what is a Node.js file:
换句话说,使用Node.js,您不必等待,可以继续执行下一个任务。 这是它如此高效的原因之一。 现在,什么是Node.js文件:
And last but not least, what you can do with Node.js?
最后但并非最不重要的一点是,您可以使用Node.js做什么?
Now it’s time to play a quiz of why, who, when and what for. So why use Node.js? Probably, its creator and founder Ryan Dahl can shed a light. The major advantage, he tells, is that this JavaScript language doesn’t block I/O — meaning input/output communication method. Here, though, the developer community has two views. Some argue, that applications with many CPU cycles can crash then. Others say it’s not a big deal at all, as Node code works in small processes.
现在是时候来问一下为什么,谁,何时何地的测验了。 那为什么要使用Node.js? 它的创建者和创始人Ryan Dahl可能可以阐明这一点。 他告诉我们,主要优点是该JavaScript语言不会阻止I / O,这意味着输入/输出通信方法。 不过,在这里,开发人员社区有两种观点。 有人认为,具有许多CPU周期的应用程序可能会崩溃。 其他人则说,这根本不是什么大问题,因为Node代码可以在小型进程中工作。
Another benefit is single-threaded event loop, that is responsible for abstracting I/O from external requests. Speaking plainly, this means that Node.js initiates the event loop at the start, processes the input, and begins the order of operations. Dev geeks interested in exploring it can read Node.js event loop.
另一个好处是单线程事件循环 ,它负责从外部请求中抽象I / O。 简而言之,这意味着Node.js从头开始启动事件循环,处理输入,并开始操作顺序。 有兴趣探索它的开发极客可以阅读Node.js事件循环 。
Jim Hirschauer of Crafter Software made few realizations on why use Node.js. We think they highlight the essence and what Node.js is good for:
Crafter Software的Jim Hirschauer对于使用Node.js的原因几乎没有意识到 。 我们认为它们突出了本质以及Node.js的优点:
Google JavaScript engine
Google JavaScript引擎
Translation: fast and scalable web apps in a result.
翻译:结果是快速且可扩展的Web应用程序。
For server-side applications
对于服务器端应用程序
Meaning, Node.js is an event-driven model of programming, where the flow is determined by certain events (user actions, messages, etc.).
意思是,Node.js是事件驱动的编程模型,其中流程由某些事件(用户动作,消息等)确定。
Easier and scalable
更容易和可扩展
That is, to make
也就是说,使
apps like Uber or Trello and scaling out on multi-CPU servers.
Per-process and across servers
每进程和跨服务器
Translation: Node.js can scale on individual process basis spreading out the load across multi-core servers.
转换:Node.js可以在单个进程的基础上扩展,从而将负载分散到多核服务器上。
This all seems a bit tough, we realize. So behold a summary of coherent benefits to using Node.js.
我们意识到,这一切似乎有些艰难。 因此,总结一下使用Node.js的相关好处。
Well, this should clear the picture for you a bit more. But wait, did you know NASA also uses Node.js?
好吧,这应该为您清除更多图片。 但是,等等,您知道NASA也使用Node.js吗?
Showing incredible pace (close to 100% growth in use every year), Node.js has become a universal platform for web apps. Companies like PayPal, Walmart use Node for enterprise applications too. Trends building up within Node community are micro-services, real-time applications, and Internet of Things (IoT). But more on that later.
Node.js以惊人的速度发展(每年使用量增长近100%),已成为Web应用程序的通用平台。 PayPal,Walmart等公司也将Node用于企业应用程序。 微服务,实时应用程序和物联网(IoT)是Node社区中建立的趋势。 但是稍后会更多。
With almost 4 million users by early 2017, Node.js surely does not lack top-level companies that work with it. For instance, what was our previous reference to NASA all about? Well, this is the truth. The agency in partnership with UTC Aerospace Systems has designed end-to-end system for live data processing. It is used in astronauts’ spacesuits and has been build with Node.js.
截至2017年初,Node.js拥有近400万用户 ,因此肯定不缺少与其合作的顶级公司。 例如,我们之前提到的NASA到底是什么? 好吧,这是事实。 该机构与UTC Aerospace Systems合作,设计了用于实时数据处理的端到端系统。 它用于宇航员的太空服,并已使用Node.js构建。
If you’ve read our previous post about top companies using Node.js, you already know about Netflix, Microsoft, Uber and more. Though that is far from all great examples. Capital One, a huge financial corporation, runs numerous projects with Node.js because of short Node.js development cycles. Advertising agencies, like Fusion Marketing, create interactive customer experiences. Walmart in retail, Uber in transportation, Google, Twitter, GoDaddy, Skycatch… it may take hours to cover them all.
如果您已经阅读了有关使用Node.js的顶级公司的先前文章,那么您已经了解Netflix,Microsoft,Uber等。 尽管这远非所有出色的例子。 大型金融公司Capital One由于Node.js的开发周期短 ,因此与Node.js一起运行多个项目。 广告代理(例如Fusion Marketing )可创建交互式客户体验。 零售业中的沃尔玛,运输业中的优步,谷歌,推特,GoDaddy,Skycatch……可能需要数小时才能涵盖所有内容。
There’s also a series of Node.js Enterprise conversations, where each episode is devoted to a separate Node.js use case. Like this one, where Adam Geitgey, director of software engineering at Groupon, talks about how the platform helped them to expand.
还有一系列的Node.js Enterprise对话,其中每一集都专门讨论一个单独的Node.js用例。 与此类似,Groupon的软件工程总监Adam Geitgey在这里谈论平台如何帮助他们扩展。
One of the results of Node.js use at Groupon was 50% reduction of page load times. How about that! Let’s talk a bit more about Node.js success cases.
Groupon使用Node.js的结果之一是页面加载时间减少了50% 。 那个怎么样! 让我们再谈谈Node.js成功案例。
Groupon rebuilt its own website with Node.js moving from Ruby on Rails. Despite Ruby was ok, over time it became harder to maintain the website with each new update. Node.js was chosen for a bunch of reasons: it supported scaling projects, provided better performance and tolerated old Ruby code. In the end of the process, team even released a few own-made JavaScript libraries: Gofer and Node cached. As a bottom line, Groupon is using Node.js in many ways now:
Groupon使用Node.js从Ruby on Rails重建了自己的网站。 尽管Ruby没问题,但随着时间的推移,每次更新都很难维护网站。 选择Node.js的原因有很多:它支持扩展项目,提供更好的性能并可以容纳旧的Ruby代码。 在该过程的最后,团队甚至发布了一些自制JavaScript库: Gofer和Node cached 。 最重要的是,Groupon现在以多种方式使用Node.js:
Skycatch is a data company working with commercial drones data. And while creating raw SQL is hard and long, Skycatch allows to do it in an easier way and simplify data extraction from websites. Andre Deutmeyer and the team of 20 developers had the task to architect and deliver data to customers quickly. They chose Node.js and basked in wins, like:
Skycatch是一家处理商业无人机数据的数据公司。 尽管创建原始SQL既困难又漫长,但Skycatch允许以一种更简单的方式进行操作,并简化了从网站提取数据的过程。 Andre Deutmeyer和由20名开发人员组成的团队的任务是快速设计并向客户交付数据。 他们选择了Node.js并赢得了胜利,例如:
Rick Adam, a team leader of 25 developers at Lowe’s, had a task to manage apps at presentations tiers. In order to rebuild a monolithic app back in 2007 company chose Node.js as in those days even minor changes in an app text required the whole app to be patched, while Node.js provided flexibility in that regard. This choice resulted in the following:
Lowe’s的25位开发人员的团队负责人Rick Adam的任务是在演示层管理应用程序。 为了重建整体应用程序,早在2007年,公司就选择Node.js,因为在那时,即使对应用程序文本进行细微更改也需要修补整个应用程序,而Node.js在这方面提供了灵活性。 该选择导致以下结果:
As with Node.js one can use JavaScript on the server, this means one can write JavaScript outside the browser. Additionally, Node.js has the same strength as JavaScript. And it is based on events. These are the 3 whales Node.js firmly stands on.
与Node.js一样,人们可以在服务器上使用JavaScript,这意味着可以在浏览器之外编写JavaScript。 此外,Node.js具有与JavaScript相同的优势。 它基于事件。 这是Node.js坚守的三头鲸鱼。
We can build fast real-time apps like a chat, or an upload system, or any app that has to respond to big number of requests. And we already knew that by now, right?
我们可以构建快速的实时应用程序,例如聊天,上传系统或任何必须响应大量请求的应用程序。 现在我们已经知道了,对吧?
So what can be Node.js used for actually? When to use Node.js and what is it good for? Well, here are few uses that you can name to clients, and examples of what could Node.js be used for.
那么Node.js实际可以用来做什么呢? 何时使用Node.js,这有什么用? 好了,这里有一些您可以命名给客户端的用途,以及Node.js可以用作什么的示例。
Streaming data
流数据
Streaming data Such as file uploading in real time, file encoding while uploading, building proxies between data layers.
流数据 例如实时文件上传,文件上传时编码,在数据层之间建立代理。
Single page apps
单页应用
Single page apps Modern web applications, heavy on processing on the client side. Positive response times and sharing data between the server and the client make a good fit for such apps.
单页应用 现代的Web应用程序,侧重于在客户端进行处理。 积极的响应时间以及服务器与客户端之间共享数据非常适合此类应用程序。
Web applications
网络应用
Web applications Classic web apps on the server side, using Node.js to carry HTML. One of the main benefits in this regard is more SEO-friendly content.
网络应用 服务器端的经典Web应用程序,使用Node.js承载HTML。 在这方面的主要好处之一是对SEO友好的内容。
Chats / RTAs
聊天/ RTA
Chats / RTAs Lightweight real-time applications, like messaging apps interfaces, Twitter, chat software. A classic chat would be a great example of Node.js use. Simple, intensive on data and across multiple devices.
聊天/ RTA 轻量级实时应用程序,例如消息传递应用程序界面,Twitter,聊天软件。 经典的聊天将是Node.js使用的一个很好的例子。 简单,密集的数据和跨多个设备。
APIs
蜜蜂
APIs REST / JSON programming interfaces and exposing databases or web services through it. No worries about conversion between systems.
蜜蜂 REST / JSON编程接口,并通过它公开数据库或Web服务。 无需担心系统之间的转换。
Proxy
代理
Proxy To deploy Node.js as proxy to handle connections in non-blocking way. Great for app working with external services, exporting and importing lots of data.
代理 将Node.js部署为代理以非阻塞方式处理连接。 非常适合与外部服务配合使用,导出和导入大量数据的应用程序。
Dashboards
仪表板
Dashboards Web application or system monitoring dashboards, enabling tracking user actions. Node.js also can visualize such interactions for you in real-time.
仪表板 Web应用程序或系统监视仪表板,可跟踪用户操作。 Node.js还可以为您实时可视化此类交互。
Yet, Node.js is evolving fast and not only web application building is possible. Check out these alternative Node.js projects that are still in making.
但是,Node.js发展Swift,不仅可以构建Web应用程序。 查看仍在制作中的这些替代Node.js项目。
NodeOS: an operating system built on top of Linux, with JavaScript as primary runtime and NPM as packaging manager.
NodeOS :在Linux之上构建的操作系统,以JavaScript为主要运行时,以NPM为打包管理器。
Node-Webkit: a runtime environment for Node.js applications. Simple app packaging process — zip it, add information and deploy cross-platform.
Node-Webkit :Node.js应用程序的运行时环境。 简单的应用程序打包过程-压缩,添加信息并部署跨平台。
Log.io: a log monitoring tool, using Socket.io library. All changes you are following, you can track in real-time and in browser.
Log.io :使用Socket.io库的日志监视工具。 您遵循的所有更改都可以在浏览器中实时跟踪。
Nodecast: an application that sends images and videos from your mobile phone to PC. Inspired by Google Chromecast.
Nodecast :一个将图像和视频从您的手机发送到PC的应用程序。 受到Google Chromecast的启发。
Nexe: a utility for Node.js app distribution by creating a single executable. Though it only works on Linux and MacOS X so far.
Nexe :通过创建单个可执行文件来分发Node.js应用程序的实用程序。 尽管到目前为止,它仅在Linux和MacOS X上有效。
And that is not all, dear stoic readers who are still reading this. Enterprise-scale businesses and projects are also embracing Node.js.
亲爱的坚忍的读者们,还不止这些,他们还在读这本书。 企业级企业和项目也都在使用Node.js。
We have already mentioned Walmart, Paypal and Netflix. Fast delivery and iterations are what Node.js enables and what makes it stand out. Top developers, loving all things new, and who can do anything in JavaScript, like the high performance of Node.js. One famous example was the choice of Bill Scott, who is now VP at PayPal, when faced with a career choice.
我们已经提到过沃尔玛,贝宝和Netflix。 快速交付和迭代是Node.js支持的功能以及使其脱颖而出的原因。 顶级开发人员,热爱所有新事物,并且可以使用JavaScript进行任何操作,例如Node.js的高性能。 一个著名的例子是当面对职业选择时,现任贝宝(PayPal)副总裁的比尔·斯科特(Bill Scott)的选择。
Why go to Facebook and do PHP, when you can go to Paypal and do Node.js. — Bill Scott, VP of engineering at PayPal
当您可以转到Paypal并执行Node.js时,为什么要去Facebook并使用PHP。 — PayPal工程副总裁Bill Scott
So why enterprises alike go with Node.js? Reduced page load times, ease of maintaining, the number of servers reduction might hold some answers. In addition, a new architecture type of Node.js, called micro-services, helps in handling numerous changes to enterprise software. Under this approach, you can create applications from smaller pieces, and develop those pieces separately. No harm to overall functioning.
那么,为什么企业都使用Node.js? 减少页面加载时间,易于维护,减少服务器数量可能会带来一些答案。 另外,称为微服务的Node.js的新体系结构类型有助于处理企业软件的众多更改。 使用这种方法,您可以从较小的块创建应用程序,然后分别开发这些块。 不会损害整体功能。
There are also developers who prefer full-stack unified solutions. In practice, top 4 technologies used along with Node.js are:
还有一些开发人员更喜欢全栈统一解决方案。 实际上,与Node.js一起使用的前4种技术是:
What are the potential application areas of Node.js?
Node.js的潜在应用领域是什么?
Basically, any business using Node.js can: employ less developers, use less servers, decrease page load times. For more thoughts on this, you may watch the next video, where CTO and architect manager of Nodesource talk about Node.js.
基本上,任何使用Node.js的企业都可以:雇用更少的开发人员,使用更少的服务器,减少页面加载时间。 有关此问题的更多想法,您可以观看下一个视频,在该视频中,CTO和Nodesource的架构经理讨论Node.js。
One final thing in our trip to Nodeland are some practical advises about running this toolset. We should start with process managers to deploy applications. To make your life easier, use NPM, PM2, Adios, Strongloop or any other Node.js production manager.
我们前往Nodeland的最后一件事是有关运行此工具集的一些实用建议。 我们应该从流程管理器开始以部署应用程序。 为了使您的生活更轻松,请使用NPM,PM2,Adios,Strongloop或任何其他Node.js生产经理。
Don’t do apps heavy on CPU with Node.js. Programming things like artificial intelligence (AI), video encoding software, and such software that loads the processor, better use another solution. Node.js has a 1.5 Gb memory limit, though you can apply clustering to fork processes into smaller ones.
不要使用Node.js 做占用CPU过多的应用 。 对诸如AI(AI),视频编码软件之类的程序进行编程,以及加载处理器的此类软件,最好使用其他解决方案。 Node.js的内存限制为1.5 Gb,尽管您可以将群集应用于将进程分叉到较小的进程中。
Node.js servers are not great for computational and data-intensive tasks. Thus, it is better to split such tasks into micro-services and deploy separately.
Node.js服务器不适用于计算和数据密集型任务。 因此,最好将此类任务拆分为微服务并分别部署。
Don’t run a Node.js app through port 80. Use a reverse proxy in front of the app, like Nginx for example. In this way you protect servers from internet traffic and spread the load balance.
不要 通过端口80 运行 Node.js应用程序。 在应用程序的前面使用反向代理,例如Nginx。 这样,您可以保护服务器免受Internet流量的影响,并分散负载平衡。
Install SSL for security reasons. Always use a reverse proxy, check vulnerabilities in SSL and fix the possible issues. Do basic security checks from time to time. Do not use outdated versions of Node.js and Express.
出于安全原因安装SSL 。 始终使用反向代理,检查SSL中的漏洞并解决可能的问题。 不时进行基本安全检查。 不要使用过时的Node.js和Express版本。
Think of infrastructure and architecture ahead of app deployment. Experts recommend developing an application within a private network (VPN), so you can allow only trusted connections.
在应用程序部署之前考虑基础架构和体系结构。 专家建议在专用网络(VPN)中开发应用程序,这样您就只能允许信任的连接。
You probably ask a rhetorical question: why on Earth have we poured our souls out about Node.js? The answer is simple — we love both Node.js and JavaScript. At ThinkMobiles, we like developing web and mobile applications using this language. We like Node.js for its ease and speed, for cross-platform nature.
您可能会提出一个反问:一个为什么我们在地球上为Node.js倾注了灵魂? 答案很简单-我们喜欢Node.js和JavaScript。 在ThinkMobiles ,我们喜欢使用这种语言开发Web和移动应用程序。 我们喜欢Node.js,因为它的易用性和速度以及跨平台的特性。
Thank you for reading. If you like leave some ?.
感谢您的阅读。 如果您愿意,留下一些吗?
If you want to read more check out here.
如果您想阅读更多内容,请点击此处 。
翻译自: https://www.freecodecamp.org/news/what-exactly-is-node-js-and-why-should-you-use-it-8043a3624e3c/