Javascript Node.js服务器赢得';不能在64位windows 7上启动
我的设置似乎有点问题,我目前在windows 7 64位计算机上安装了Javascript Node.js服务器赢得';不能在64位windows 7上启动,javascript,node.js,Javascript,Node.js,我的设置似乎有点问题,我目前在windows 7 64位计算机上安装了node-v//v0.10.29 // Include http module. var http = require("http"); http.createServer(function (request, response) { request.on("end", function () { response.writeHead(200, { 'Content-Type'
node-v//v0.10.29
// Include http module.
var http = require("http");
http.createServer(function (request, response) {
request.on("end", function () {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello HTTP!');
});
}).listen(8080);
这是我通过节点http.js运行的文件。除此文件外,文件夹中没有其他内容
运行这个小坏蛋:node-inspector&node--debug http.js
在cmd中返回以下内容:
Node Inspector v0.7.4
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
我可以导航到http://127.0.0.1:8080
以及建议的url,使用debug?etc导航
为我提供了一个控制台,类似于chrome的开发者工具
导航到不带参数的url时,我将无法获取带有请求的404
使用上述标题:
Remote Address:127.0.0.1:8080
Request URL:http://127.0.0.1:8080/
Request Method:GET
Status Code:404 Not Found
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:127.0.0.1:8080
Pragma:no-cache
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Chrome/35.0.1916.153 Safari/537.36
Response Headersview source
Connection:keep-alive
Content-Type:text/html
Date:Thu, 17 Jul 2014 23:07:13 GMT
Transfer-Encoding:chunked
X-Powered-By:Express
那么如何连接到node.js和Windows7
// Include http module.
var http = require("http");
http.createServer(function (request, response) {
request.on("end", function () {
// ...
});
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello HTTP!');
}).listen(8080);
为了理解这个问题,我们可以做一些实验
在响应和请求结束事件周围添加控制台日志
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
输出:
response start
response end
request end
然后注释掉这一行响应。结束
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
//response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
现在请求被卡住了。永远不会发出结束事件
response start
response end
所以结论是请求的结束事件只能在response.end完成后触发。不应将您的响应放在请求的结束事件主体中
为了理解这个问题,我们可以做一些实验
在响应和请求结束事件周围添加控制台日志
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
输出:
response start
response end
request end
然后注释掉这一行响应。结束
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
//response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
现在请求被卡住了。永远不会发出结束事件
response start
response end
所以结论是请求的结束事件只能在response.end完成后触发。不应将您的响应放在请求的结束事件主体中
为了理解这个问题,我们可以做一些实验
在响应和请求结束事件周围添加控制台日志
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
输出:
response start
response end
request end
然后注释掉这一行响应。结束
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
//response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
现在请求被卡住了。永远不会发出结束事件
response start
response end
所以结论是请求的结束事件只能在response.end完成后触发。不应将您的响应放在请求的结束事件主体中
为了理解这个问题,我们可以做一些实验
在响应和请求结束事件周围添加控制台日志
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
输出:
response start
response end
request end
然后注释掉这一行响应。结束
console.log("response start");
response.writeHead(200, {'Content-Type': 'text/plain'});
//response.end('Hello World\n');
console.log("response end");
request.on("end", function () {
console.log("request end");
});
现在请求被卡住了。永远不会发出结束事件
response start
response end
所以结论是请求的结束事件只能在response.end完成后触发。您不应该将响应放在请求的结束事件主体中我相信我发送的文件是node http.js
或http.js
,不是吗?我相信我发送的文件是node http.js
或http.js
,否?我相信我发送的文件是node http.js
或http.js
,否?我相信我发送的文件是node http.js
或http.js
,否?除了添加语法错误外,这不会改变OP的代码。答案改进了很多!除了添加一个语法错误外,这不会改变OP代码中的任何内容。答案改进了很多!除了添加一个语法错误外,这不会改变OP代码中的任何内容。答案改进了很多!除了添加一个语法错误外,这不会改变OP代码中的任何内容。答案改进了很多!