第一個 服務器 的例子就從 “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 程序執行
> node example.js
Server running at http://127.0.0.1:8124/
文檔中所有的例子都可以這么執行。