概要
一个用Node.js写的web server例子,这个例子将返回’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/
文档中所有的例子都可以用类似的方法运行