5 服务端(响应:wirteHead+end )

res.wirteHead

1.用第三方模块mime,自动判断书写响应报文文件res.writeHead参数2

let  type =  mime.getType("realpath")
//响应报文 wirteHead(),返回给客户端的状态码和内容
let  type =  mime.getType("realpath")
app.on(request, (req, res) => {

        res.wirteHead(参数1, {
        "content:type :type ; charset=utf8 "  //参数2
        }
})  

res.writeHead参数1

res.writeHead参数1 解释
200 请求成功
404 请求没有找到,例如图片没找到
500 服务器端错误,一般和客户端没关系
400 客户端请求有语法错误,请求路径,请求参数错误

res.writeHead参数2

res.writeHead参数2 解释
HTML text/html
CSS text/css
JS application/javascript
img image/jpeg
json application/json
纯文本 text/plain

res.end

app.on(request, (req, res) => {
        res.end("

哈哈

"
) })

你可能感兴趣的:(5 服务端(响应:wirteHead+end ))