(翻譯)《Hands-on Node.js》—— Introduction


今天開始會和大熊君{{bb}}一起着手翻譯node的系列外文書籍,大熊負責翻譯《Node.js IN ACTION》一書,而我暫時負責翻譯這本《Hands-on Node.js》(下載),為方便理解不采用直譯的方式,若有翻譯不當的地方還請不吝賜教,我會及時堪正。

引言

在09年歐洲JSConf大會上,一位叫做Ryan Dahl的年輕程序員介紹了一項他所負責的項目。該項目結合了谷歌V8 Javascript引擎以及event loop機制,從而可以使用JS來創建服務端平台。該項目跟其它服務端JS平台不太一樣:所有的I/O基元都是事件驅動的,沒有其它捷徑。借力於強大又簡單的JS,原本基於異步讀寫的應用任務,由復雜變得簡單好實現。

Dahl演講完畢時會場掌聲不斷,他的項目也取得了空前的發展,日益流行並被廣泛采用。

該項目被命名為Node.js,時下常被程序員們簡稱為“Node”。Node提供了純事件驅動的、無阻塞的架構來創建高並發的程序,使用它能讓你輕松構造快速又可擴展的網絡服務。

Introduction

At the European JSConf 2009, a young programmer by the name of Ryan Dahl, introduced a project
he had been working on. This project was a platform that combined Google’s V8 JavaScript engine
and an event loop to create a server-side platform programmable in JavaScript. The project took a
different direction from other server-side JavaScript platforms: all I/O primitives were event-driven,
and there was no way around it. Leveraging the power and simplicity of JavaScript, it turned the
difficult task of writing asynchronous applications into an easy one. Since receiving a standing
ovation at the end of his talk, Dahl’s project has been met with unprecedented growth, popularity
and adoption.
The project was named Node.js, now known to developers simply as ‘Node’. Node provides purely
evented, non-blocking infrastructure for building highly concurrent software.
Node allows you to easily construct fast and scalable network services.
原文

 

為何Node如此突然地、呈指數倍地流行起來?

服務端JS其實已經出現多時了,是什么讓Node平台如此引人注目?

環顧之前的那些服務端JS的實現,更着重處理的地方還是把其它平台(比如Ruby、PERL、Python)上常用的方法遷移到JS中,而JS本身不露鋒芒。Node跳過了這種處理,並表示——“讓我們使用web上那些可成功驅動事件的編程模塊,來輕松創建可擴展的服務,並讓這種方式無可替代、無所不能”。

可以說JS本身為Node的成功做出了很大的貢獻,但這點不能解釋Node之前的其它服務端項目為何沒有流行起來。雖然JS的確具備了普遍性,但對此Ryan Dah指出,不像其它服務端中JS所做的嘗試,統一客戶端和服務端的語言並非Node的首要目標。

在我看來,Node成功的主要因素有三個:

1. Node很簡單——使用了事件驅動I/O編程,是最好的I/O編程方式,比起其它現有平台的實現更易懂、更成功。

2. Node很精練——它不會試着去解決全部問題,而是依靠清晰明確的功能性API為處理internet協議奠定了基礎和支持。

3.Node不妥協——不會試着去兼容之前的軟件,並讓人們重新審視並首肯了其定位。

Why the sudden, exponential popularity?

Server-side JavaScript has been around for some time, what makes this platform so appealing?
In previous server-side JavaScript implementations, javascript was the raison d’etre, and the
approach focussed on translating common practices from other platforms like Ruby, PERL and
Python, into JavaScript. Node took a leap from this and said: “Let’s use the successful event-driven
programming model of the web and use it to make an easy way to build scalable servers. And let’s
make it the only way people can do anything on this platform.”.
It can be argued that JavaScript itself contributed to much of Node’s success, but that would not
explain why other the server-side projects proceeding Node have not yet come close in popularity.
The ubiquity of JavaScript surely has played a role, but, as Ryan Dahl points out, unlike other Serverside
JavaScript attempts, unifying the client and server into a common language was not the primary
goal for Node.
In my perspective there are three factors contributing to Node’s success:
1. Node is Easy - Node makes event-driven I/O programming, the best way to do I/O programming,
much easier to understand and achieve than in any other existing platform.
2. Node is Lean - Node does not try to solve all problems. It lays the foundation and supports
the basic internet protocols using clean, functional APIs.
3. Node does not Compromise - Node does not try to be compatible with pre-existing software,
it takes a fresh look at what many believe is the right direction.
原文

 

本書涵蓋內容

我們會分析為何Node不走尋常路,以及為何你應該使用Node、如何使用Node。我們會從一個概述開始,然后很快轉入模塊化代碼。在最終你將懂得創建和測試你自己的Node模塊、服務端/客戶端應用,並享受Node的便捷和各種API

What does this book cover?

We will analyze what makes Node a different proposal to other server-side solutions, why you
should use it, and how to get started. We will start with an overview but quickly dive into some
code module-by-module. By the end of this book you should be able to build and test your own
Node modules, service producers/consumers and feel comfortable using Node’s conventions and
API.
原文

 

本書沒有涵蓋的內容

本書並不打算介紹完全部的Node API,但我們會介紹那些作者認為的大部分應用所需要的、常用的部分。

本書也不會涉及任何Node框架。Node是一個很棒的創建框架的工具,其中也不乏好用的框架,比如簇管理的、跨進程通訊的、web框架、網絡流量整合工具、游戲引擎等等。不過在你開始接觸框架之前,你應該先熟悉Node的基礎架構並了解它為這些構建模塊提供了些什么。

What does this book not cover?

This book does not attempt to cover the complete Node API. Instead, we will cover what the author
thinks is required to build most applications he would build on Node.
This book does not cover any Node frameworks; Node is a great tool for building frameworks and
many are available, such as cluster management, inter-process communication, web frameworks,
network traffic collection tools, game engines and many others. Before you dive into any of those
you should be familiar with Node’s infrastructure and what it provides to these building blocks.
原文

 

閱讀本書的先決條件

本書假設你之前並未了解任何Node知識,但各種例子的代碼畢竟是用JS書寫的,所以熟悉JS這門語言有助你理解。

Prerequisites

This book does not assume you have any prior knowledge of Node, but the code examples are written
in JavaScript, so familiarity with the JavaScript language will help.
原文

 

練習

本書在部分小節會有練習題,你可以在書的最后找到這些練習的答案,但我建議你先自行動手解題,棘手處可查閱本書或訪問http://nodejs.org查閱完整的API文檔。

Exercises

This book has exercises in some chapters. At the end of this book you can find the exercise
solutions, but I advise you to try do them yourself. Consult this book or use the comprehensive
API documentation on the official http://nodejs.org¹ website.
原文

 

源碼

你可以在GitHub上找到本書的部分源碼和練習:

https://github.com/pgte/handson_nodejs_source_code

或者直接下載它們:

https://github.com/pgte/handson_nodejs_source_code/zipball/master

Source code

You can find some of the source code and exercises used in this book on GitHub:
https://github.com/pgte/handson_nodejs_source_code²
or you can download it directly:
https://github.com/pgte/handson_nodejs_source_code/zipball/master³
原文

 

本書的引導方向

在閱讀完本書后,你將了解Node API並可以從事研究那些基於Node所搭建出來的東西(比如適配器、框架和模塊),讓我們啟程吧。

Where will this book lead you?

By the end of it, you should understand the Node API and be able to pursue the exploration of other
things built on top of it, being adaptors, frameworks and modules.
Let’s get started!
原文

donate


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM