在试简易聊天室这个案例 在建立服务器的时候有问题
发布于 11 年前 作者 cooldrine 4525 次浏览 最后一次编辑是 8 年前

var app = require(‘express’).createServer(), io = require(‘socket.io’).listen(app);

app.listen(3000);

app.get(’/’, function (req, res) { res.sendfile(__dirname + ‘/index.html’); });

io.sockets.on(‘connection’, function (socket) { socket.emit(‘welcome’, { text: ‘OH HAI! U R CONNECTED!’ }); });

目录下面有index.html 报错内容是: TypeError: Arguments to path.join must be strings at f (path.js:204:15) at Object.filter (native) at exports.join (path.js:209:40) at exports.send (C:\Users\Administrator\nodejs\demo\socket.io_express\node_modules\express\node_modules\connect\lib\middleware\static.js:129:20) at ServerResponse.res.sendfile (C:\Users\Administrator\nodejs\demo\socket.io_express\node_modules\express\lib\response.js:186:3) at io.sockets.on.socket.emit.text (C:\Users\Administrator\nodejs\demo\socket.io_express\app.js:7:7) at callbacks (C:\Users\Administrator\nodejs\demo\socket.io_express\node_modules\express\lib\router\index.js:272:11) at param (C:\Users\Administrator\nodejs\demo\socket.io_express\node_modules\express\lib\router\index.js:246:11) at pass (C:\Users\Administrator\nodejs\demo\socket.io_express\node_modules\express\lib\router\index.js:253:5) at Router._dispatch (C:\Users\Administrator\nodejs\demo\socket.io_express\node_modules\express\lib\router\index.js:280:5)

哪里出问题了额
4 回复

请问你的index.html在哪里呢? 如果在 public目录下 那么res.sendfile(__dirname + ‘/public/index.html’);

再顶一下。。

我也是遇到同样的问题,百度谷歌半天无果…求大神解决

八成是版本的问题,旧path.join可以传入非string参数,新path.join传入非string参数就会报这个错 http://nodejs.org/api/path.html#path_path_join_path1_path2 所以去看看socket.io有没有新版本

回到顶部