前言

Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型,使其轻量又高效。Node.js 的包管理器 npm,是全球最大的开源库生态系统。

使用node 实现的web 服务器示例,它返回'Hello World':

var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');```

将上述代码保存为example.js,并使用如下命令执行这个服务程序:

node example.js Server running at http://127.0.0.1:8124/```

文档中的其他示例,均可以类似的方式执行。

下面让我们开始nodejs之旅。