1 var http = require('http'); 2
3 http.createServer(function (request, response) { 4 response.writeHead(200, {'Content-Type': 'text/plain'}); 5 response.end('Hello World\n'); 6 }).listen(8124); 7
8 console.log('Server running at http://127.0.0.1:8124');
要运行服务器,须要将代码输入一个名为 example.js 的文件并经过 node 程序执行node
> node example.js Server runing at http://127.0.0.1:8124/
文档中全部的例子均可以相似地运行。 web