我是一个新手,正在学习node.js。尝试让控制台在请求结束时打印内容。我尝试访问localhost:8080和localhost:8080/,但终端没有任何输出。有什么想法吗?我这样做是因为当我运行此示例时,在http://tutorialzine.com/2012/08/nodejs-drawing-game/上运行演示时,终端显示套接字已启动但未呈现index.html页。所以我无法弄清楚为什么这段代码用于为他人提供静态文件无法正常工作。
var static = require('node-static');
//
// Create a node-static server instance to serve the './public' folder
//
// var file = new(static.Server)('./');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
console.log("ended");
});
}).listen(8080);
app
是http.Server
的一个实例。但在 Express 3.x 中,app
变成了一个function
,因此您不能简单地对其进行listen()
操作。请查看 2.x 到 3.x 迁移指南,特别是 Socket.IO 兼容性。 - Jonathan Lonowski