[英]node.js simple web server request life cycle
I'm new to server side Javascript so to Node.js. 我是服务器端Java语言的新手,所以对Node.js还是新手。 Well, Here I'm trying some very simple thing such as
好吧,我在这里尝试一些非常简单的事情,例如
var http = require("http");
http.createServer(function(request, response) {
console.log("node server");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(2424);
As I see the result whenever I send a request to the server console.log("node server");
正如我看到的结果,每当我向服务器
console.log("node server");
发送请求时 executes twice. 执行两次。 Why it's happening, how node (or
http.createServer
) serves a request? 为什么会发生这种情况,节点(或
http.createServer
)如何处理请求?
By default, all requests to pages also asks for the favicon. 默认情况下,所有对页面的请求也会要求提供图标。
To check what resources are being requested on a single page visit, try the additional console.log. 要检查单页访问中请求的资源,请尝试其他console.log。
console.log(request.path);
Just a hunch, but this is probably the most likely cause. 只是预感,但这可能是最可能的原因。
发布请求时,您需要检查请求代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.