var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
这个示例代码首先通过 require 方法把 HTTP 库包含到程序中来。有许多语言都有
包含其他库这一方法, Node 用的是 CommonJS 模块风格。 Node 模块将在第 8 章详
细介绍,当前需要了解的是, HTTP 库所具有的功能已经赋给了 http 对象。
runing hello.js
node hello,js
result:
Server running at http://127.0.0.1:8124/