node.js http.js :类型错误:对象 200 没有方法“toLowerCase”;

发布于 2024-11-02 13:08:09 字数 228 浏览 1 评论 0原文

我现在正在学习node.js。每当我运行 node example.js 时,它都会说

http.js:529 var key = name.toLowerCase();

<前><代码> ^

类型错误:对象 200 没有方法“toLowerCase”

这是 FF 和 chrome 的已知问题。

I'm learning node.js now. Whenever I ran node example.js it says

http.js:529
var key = name.toLowerCase();

                     ^

TypeError: Object 200 has no method 'toLowerCase'

is this known issue with FF and chrome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月下伊人醉 2024-11-09 13:08:09

Node.js 与 Firefox 或 Chrome 没有任何关系,只是与 Chrome 共享相同的 javascript 引擎(V8)。因此,这不是 Chrome 或 FF 的问题,而是 Node.js、V8 或您自己的代码之一的问题。

问题可能是您向函数传递了错误类型的参数,例如数字而不是字符串。

// For example
response.write(200);
// Will fail because 200 is a number, not a string

Node.js has nothing to do with Firefox or Chrome, except for sharing the same javascript engine (V8) with Chrome. So it's not an issue with Chrome or FF, but with one of Node.js, V8, or your own code.

The problem is probably that you passed the wrong type of argument to a function, such as a number instead of a string.

// For example
response.write(200);
// Will fail because 200 is a number, not a string
你げ笑在眉眼 2024-11-09 13:08:09

这是 FF 的已知问题吗?
镀铬。

你在浏览器中运行node.js吗? Node.js 应该通过命令作为服务器运行
线。

is this known issue with FF and
chrome.

Are you running node.js in the browser?. Node.js should be run as a server from the command
line.

不即不离 2024-11-09 13:08:09

看起来 nameNumber 值为 200。Number 没有 toLowerCase 方法。如果您希望 name 中包含非数字值,请先将其转换为字符串 String(name).toLowerCase()

It looks like name has a Number value of 200. Number does not have a toLowerCase method. If you are expecting non-numeric values in name, convert it to string first String(name).toLowerCase().

咆哮 2024-11-09 13:08:09

我自己刚刚遇到此消息,使用 net.tutsplus.com

// Doesn't work with node.js 0.4.7
var sys = require("sys"),  
    http = require("http");  

http.createServer(function(request, response) {  
    response.sendHeader(200, {"Content-Type": "text/html"});  
    response.write("Hello World!");  
    response.close();  
}).listen(8080);  

sys.puts("Server running at http://localhost:8080/");

要使其正常工作,请引用 @Na7coldwater 和 @Chandru 推导的 200,并更正两个函数名称(sendHeader() 应为 setHeader() close() 应该是 end()):

// Works with node.js 0.4.7
var sys = require("sys"),  
    http = require("http");  

http.createServer(function(request, response) {  
        response.setHeader("200", {"Content-Type": "text/html"});  
        response.write("Hello World!");  
        response.end(); 
}).listen(8080);  

sys.puts("Server running at http://localhost:8080/"); 

这是来自 nodejs.org 的当前 Hello World

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

I just ran into this message myself, using this example from net.tutsplus.com:

// Doesn't work with node.js 0.4.7
var sys = require("sys"),  
    http = require("http");  

http.createServer(function(request, response) {  
    response.sendHeader(200, {"Content-Type": "text/html"});  
    response.write("Hello World!");  
    response.close();  
}).listen(8080);  

sys.puts("Server running at http://localhost:8080/");

To get this to work, quote the 200 as deduced by @Na7coldwater and @Chandru, and correct the two function names (sendHeader() should be setHeader() and close() should be end()):

// Works with node.js 0.4.7
var sys = require("sys"),  
    http = require("http");  

http.createServer(function(request, response) {  
        response.setHeader("200", {"Content-Type": "text/html"});  
        response.write("Hello World!");  
        response.end(); 
}).listen(8080);  

sys.puts("Server running at http://localhost:8080/"); 

And here's the current Hello World from nodejs.org

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文