1. 程式人生 > >Node.js——搭建http伺服器

Node.js——搭建http伺服器

//匯入包
var http=require("http");

http.createServer(function (request,response) {  //請求  響應
    response.writeHead(200,{"Content-Type":"text/plain"});
    response.write("hello world");
    response.end();
}).listen(8888,"127.0.0.1");    //伺服器的埠號  IP地址——預設是127.0.0.1
console.log("伺服器已經啟動,請訪問地址:http://127.0.0.1:8888");