Synopsis 总述

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

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

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

  1. > node example.js
  2. Server running at http://127.0.0.1:8124/

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