nodeJS内容类型的TypeError

时间:2018-03-12 08:13:43

标签: node.js

我的代码在这里,我在启动服务器时遇到内容类型的类型错误。

var http = require('http');
var fs = require('fs');
var path = require('path');

var port = 4000;
http.createServer((req,res) => { 
    if(req.method==="GET"){
    res.writeHead(200, {"Content Type": "text/html"});
    fs.createReadStream("./public/index.html", "UTF-8").pipe(res);
}
else if(req.method==="POST")
{
    var data = " ";
    req.on("data", function(chunk) {data += chunk;});
    req.on("end" , function(){
        res.writeHead(200,{"Content Type": "text/html"});
        res.end('${data}');
    });
}

}).listen(port);
console.log(port)

Error i am facing

1 个答案:

答案 0 :(得分:0)

应该是Content-Type,带破折号:

res.writeHead(200, {"Content-Type": "text/html"});