一个用Node写成的web服务器,返回“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/
在本文档中的所有的例子都可以使用类似的方法运行。