2013-04-10 83 views
2

我剛剛開始學習nodejs與socket.io.js庫。我的問題與這些庫中的內容並不真正相關,而是與訪問瀏覽器如何提供這些文件有關。nodejs和socket.io.js路徑解析

在我的服務器目錄中,只有2個文件(index.html和server.js)以及node_modules目錄(用於socket.io)。在index.html的我有一個腳本標籤,包括客戶端socket.io LIB如下,

<script src="/socket.io/socket.io.js"></script> 

的relecvant服務器代碼,

var server = http.createServer(
    function(req, res) { 
     res.writeHead(200, { 'Content-type': 'text/html'}); 
     res.end(fs.readFileSync(__dirname + '/index.html')); 
    } 
    ).listen(8080, 
    function() { 
     console.log('Listening at: http://localhost:8080'); 
    } 
); 

我的問題是在這個文件目前在哪裏服務器(在index.html所在的目錄中沒有socket.io目錄)?那麼如何以及從哪裏通過網絡瀏覽器正確解析和下載?

對不起noob問題。

+0

您的服務器代碼缺少'socket.io'的服務器端設置。請參閱[本頁](http://socket.io/#how-to-use)。 – robertklep 2013-04-10 15:33:56

+0

哎呀,代碼是低於我看到它的示例代碼,無論如何phonicx的迴應幫助我瞭解它如何工作。 – 2013-04-10 15:41:00

回答

3

客戶端文件是由socket.io npm模塊自動注入的,因此當您升級npm模塊時,您的客戶端版本的socket.io會自動更新。

實際文件住在:

/usr/local/lib/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js

編輯:忘了提,當你初始化socket.io你actualy使它啓動其自身的服務器提供文件。