0

Node.JS で次のコードを実行するとエラーが発生しますが、その理由がわかりません

var http = require("http"), fs = require("fs");

function onRequest(request, response){
        request.on("end", function(){
                fs.readFile("test.txt", "utf-8", function(error, data){
                        response.writeHead(200, {"Content-Type", "text/plain"});
                        data = parseInt(data) + 1;
                        fs.writeFile('test.txt', data);
                        response.end("This page was refreshed "+data+" times!\n");
                });
        });
}

http.createServer(onRequest).listen(8080);

ここに私が得るエラーがあります:

/home/dev/nodeplay/files.js:7

response.writeHead(200, {"Content-Type", "text-plain"});
                  ^
module.js:434
  var compiledWrapper = runInThisContext(wrapper, filename, true);
                        ^
SyntaxError: Unexpected token ,
    at Module._compile (module.js:434:25)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)
    at EventEmitter._tickCallback (node.js:190:38)
4

1 に答える 1

4

この部分:{"Content-Type", "text-plain"}は無効なオブジェクトです。

つまり:

{"Content-Type": "text-plain"}
于 2013-03-29T08:03:56.267 に答える