『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 已经开启")
})
posted @ 2020-07-08 18:52  一生亦木  阅读(18)  评论(0编辑  收藏  举报