第一个服务器的例子就从 “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/
在该node.js官方文档中的所有的例子都可以使用上述方法执行。