<分区>
几个小时以来,我一直在尝试让 socket.io 与 express 4 一起工作。 我开始关注 this给了我一个工作休息 api 的教程。
为了让 socket.io 工作,我使用了命令
npm install socket.io
这将 socket.io 添加到我的 node_modules 目录中。在此之后,我编辑了我的 app.js 以包含以下代码:
//LINE above var app = espress();
var http = require('http').Server(app);
var io = require("socket.io")(http);
io.on('connection',function(socket){
console.log("A user is connected");
});
// my routes etc
在我的 (jade) View 中,我添加了以下代码:
script(src="https://cdn.socket.io/socket.io-1.2.0.js")
script.
var socket = io('http://localhost/');
现在,当我使用 npm start 运行时,我在浏览器和 npm 控制台中收到以下错误:
http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1427056664743-51 404 (not found)
据我所知,我在相关问题的几乎每个答案中都没有使用 express-generator,我做错了什么?
我试过了 this : 但结果是端口 3000 已被使用的错误。