『nodejs』http 模块
http模块
const fs = require("fs")
const path = require("path")
const http = require("http")
let data
// 设置头文件
data = fs.readFileSync("./tmp/index.html","utf-8",(err,data)=>{
console.log(data)
})
console.log(data);
const server = http.createServer((request, response) => {
response.setHeader('Content-Type', "text/html;charset=utf-8");
response.end(data);
// 设置相应内容
})
server.listen(8080, () => {
console.log("http://127.0.0.1:8080 已经开启")
})