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