创建一个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 });
时间: 2024-10-02 21:18:49