找不到模块'server.io'

时间:2016-05-08 18:40:12

标签: node.js express socket.io

我只是尝试在终端中运行命令来运行节点js服务器,在这种情况下我在终端中键入节点app.js.我不知道出了什么问题..

抛出错误;     ^

错误:找不到模块'server.io'

at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/opt/lampp/htdocs/project/socket/app.js:4:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)

var express = require('express');
var app     = express();
var server  = require('http').createServer(app);
var io      = require('server.io').listen(server);


server.listen(3000);

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

1 个答案:

答案 0 :(得分:1)

评论列表socket.io中的package.json片段,但您在app.js中尝试要求server.io。尝试将其更改为var io = require('socket.io')(server)。它看起来不像server.io就是......

有关详细信息,请参阅https://www.npmjs.com/package/socket.io