我刚刚开始使用socket.io.js库学习nodejs。我的问题实际上与这些库中的内容无关,而是关于来访的浏览器如何为文件提供服务。
在我的服务器目录中,只有两个文件(index.html和server.js)以及node_modules目录(用于socket.io)。在index.html中,我有一个脚本标记,包括客户端socket.io库,如下所示:
<script src="/socket.io/socket.io.js"></script>相关的服务器代码是,
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目录)?那么,web浏览器如何以及从哪里正确地解决和下载这些问题呢?
很抱歉问你这个菜鸟问题。
发布于 2013-04-10 23:22:31
客户端文件是由npm npm模块自动注入的,这样当您升级socket.io模块时,您的socket.io客户端版本就会自动更新。
实际文件位于:
/usr/local/lib/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js
编辑:忘记提到,当您初始化socket.io时,实际上是让它启动自己的服务器来为文件提供服务。
https://stackoverflow.com/questions/15929842
复制相似问题