node.js http.js:TypeError:对象200没有方法“toLowerCase”
我现在正在学习node.js。 每当我运行节点example.js它说
http.js:529 var key = name.toLowerCase();
^
TypeError:对象200没有方法“toLowerCase”
这是FF和铬这个已知的问题。
除了与Chrome共享相同的JavaScript引擎(V8)之外,Node.js与Firefox或Chrome无关。 所以这不是一个Chrome或FF的问题,但与Node.js,V8或您自己的代码之一。
问题可能是您将错误types的parameter passing给函数,如数字而不是string。
// For example response.write(200); // Will fail because 200 is a number, not a string
这是FF和铬这个已知的问题。
你在浏览器中运行node.js吗? Node.js应该从命令行作为服务器运行。
它看起来像name
的数值为200.数字没有toLowerCase
方法。 如果您希望name
包含非数字值,请将其转换为stringfirst String(name).toLowerCase()
。
我刚刚碰到这个消息,使用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/');
- “node.js:throw e; // process.nextTick错误“,同时尝试浏览
- NodeJS:Stream.pipe(stream)工作,但Stream.read()不
- 在Node.js中parsingHTTP数据包
- 自签名证书错误与NodeJS请求
- 通过HTTP访问LDAP目录?
- 如何创build一个从HTTP / HTTPS API获取数据的Alexa Skill(在AWS Lambda上使用Node.js的“Alexa技能工具包”)
- 为什么我在Node的HTTP服务器上有这么多连接事件?
- 如何通过XMLHttpRequest创build并保存http长连接
- Express.js HTTP请求超时