简体   繁体   English

response.writeHead上的意外令牌

[英]Unexpected token on response.writeHead

When running the following code in Node.JS it produces some error but I cant understand why 在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);

Here are the errors I get: 这是我得到的错误:

/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)

This part: {"Content-Type", "text-plain"} is an invalid object. 此部分: {"Content-Type", "text-plain"}是无效的对象。

Do you mean: 你的意思是:

{"Content-Type": "text-plain"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM