我一直在檢查其他的相關答案,如:Socket.io.js未找到(node.js的+快遞+ socket.io)
- 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
但我沒有找到解決我的問題。
這正是我所做的:
透過窗戶安裝的節點可執行文件,然後:
express node6 --hogan --ejs
cd node6
npm install
npm install socket.io
npm start
我app.js是默認的,但我加了以下幾行把它與插座連接.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。
我也試圖複製和粘貼節點http服務器和的例子與快遞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
這是錯誤頁:
Not Found
404
Error: Not Found
at Layer.app.use.res.render.message [as handle] (C:\inetpub\wwwroot\node6\app.js:29:15)
at trim_prefix (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:240:15)
at C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:208:9
at Function.proto.process_params (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:269:12)
at next (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:199:19)
at next (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:176:38)
at C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:137:5
at C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:250:10
at next (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:160:14)
at next (C:\inetpub\wwwroot\node6\node_modules\express\lib\router\index.js:176:38)
和什麼是錯誤? – webduvet 2014-08-27 11:10:14
沒有找到文件? 404 for socket.io.js – Alvaro 2014-08-27 11:12:11
@lombausch用錯誤日誌更新了問題。 – Alvaro 2014-08-27 11:30:54