【发布时间】:2014-10-20 22:06:51
【问题描述】:
我一直在检查其他相关答案,例如:
- node.js /socket.io/socket.io.js not found
- Socket.io not being served by Node.js server
- socket.io.js not found on client
- Configuring 'simplest' node.js + socket.IO + Express server
但我没有找到解决问题的方法。
这正是我所做的:
通过windows可执行安装节点然后:
express node6 --hogan --ejs
cd node6
npm install
npm install socket.io
npm start
我的 app.js 是默认的,但我添加了以下几行以将其与 socket.io 链接:
var http = require('http');
var server = http.createServer(app);
var io = require('socket.io')(server);
io.listen(http);
http.listen(3000);
Here's the complete app.js file.
我还尝试复制和粘贴 Node http server 和 Using with Express 3/4 的示例或 app.js 详细说明 in the socket.io docs,但两者他们在调用npm start 时会抛出错误。
然后,在我的 hoggn 视图中,我正在尝试以这种方式加载 socket.io:
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
据我所知,node.js 应该会自动获取它,但在我的情况下不会。为什么? 快捷版:4.2.0
这是错误页面:
未找到
404
错误:未找到
在 Layer.app.use.res.render.message [作为句柄] (C:\inetpub\wwwroot\node6\app.js:29:15)
在 trim_prefix (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:240:15)
在 C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:208:9
在 Function.proto.process_params (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:269:12)
在下一个 (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:199:19)
在下一个 (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:176:38)
在 C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:137:5
在 C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:250:10
在下一个 (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:160:14)
在下一个 (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:176:38)
【问题讨论】:
-
错误是什么?
-
找不到文件? socket.io.js 的 404
-
@lombausch 用错误日志更新了问题。
-
你真的在路径中有文件吗?
-
@lombausch 该路径在物理上不存在。在我见过的任何例子中也没有。
标签: javascript node.js express socket.io