const http = require("http");
// 使用http包可以很方便的实现简单的http服务器,createServer返回对象有listen方法监控端口
http
.createServer(function (request, response) {
// 发送HTTP头部
// HTTP状态值:200:Ok
response.writeHead(200, { "Content-Type": "text/plain" });
// 发送响应数据"hello world"
response.end("hello world\n");
})
.listen(8888);
console.log("Server running at http://127.0.0.1:8888/");