Javascript 为什么我收到 ReferenceError: Response is not defined?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43669953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:05:19  来源:igfitidea点击:

Why am I getting ReferenceError: Response is not defined?

javascriptnode.jsexpress

提问by Edward K.

I am using node.js with express. I am trying to set up a basic server, but have no idea why I am getting a response error.

我正在使用带有 express 的 node.js。我正在尝试设置基本服务器,但不知道为什么会收到响应错误。

var http = require('http');

var myServer = http.createServer(function(req,res){
    response.writeHead(200, {"Content-Type" : "text/plain"});
    response.write('Hello World');
    response.end();
});

myServer.listen(3000);

回答by Sushanth --

function(req,res)

is supposed to be

应该是

function(req, response) {

You don't have a variable named responsein the scope of the callback. That is the reason for the reference error

您没有response在回调范围内命名的变量。这就是原因reference error