标签:
在node-demo 的目录中创建一个index.js
//导入需要的包
var http = require("http");
//创建HTTP服务
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {‘Content-Type‘: ‘text/plain‘});
// Send the response body as "Hello World"
response.end(‘Hello World\n‘);
}).listen(8081);
// Console will print the message
// 访问地址
console.log(‘Server running at http://127.0.0.1:8081/‘);
在 命令行工具中 输入 node index.js 回车
系统会打印
Server running at http://127.0.0.1:8081/
这是在浏览器访问 此地址。页面中会显示 Hello World 程序运行成功!
标签:
原文地址:http://my.oschina.net/xiax/blog/477533