node学习第一篇

创建一个http服务器

 1 //app.js
 2 var http = require("http");
 3 function start(req, res){
 4     //res.writeHead(200,{"Content-Type": "text/plain"});
 5     res.writeHead(200,{"Content-Type": "text/html"});
 6     res.write("<h2>app.js</h2>");
 7     res.end("<p>Hello world!</p>");
 8 }
 9 var server = http.createServer(start).listen("3000","127.1.1.1",function(){
10     var host = server.address().address;
11     var port = server.address().port;
12     console.log("应用实例,访问地址为 http://%s:%s", host, port);
13 });

 

posted @ 2016-08-03 13:36  钟离野  阅读(255)  评论(0编辑  收藏  举报