(翻译)《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

posted @ 2015-01-11 10:12 vajoy 阅读(...) 评论(...) 编辑 收藏
Copyright © 2014 - 2017 VaJoy Studio