[root[@localhost](/user/localhost) htdocs]# node iotest.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'on'
at new Manager (/usr/local/node/bin/node_modules/socket.io/lib/manager.js:97:10)
at Object.listen (/usr/local/node/bin/node_modules/socket.io/lib/socket.io.js:71:10)
at Object.<anonymous> (/usr/local/node/htdocs/iotest.js:11:17)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
代码
var http = require('http'), io = require('/usr/local/node/bin/node_modules/socket.io');
http.createServer(function( request, response ){
response.writeHead( 200, {"Content-type": "text/html"});
response.end();
}).listen(80);
var socket = io.listen(http);
有朋友碰到过这个问题么?另外想问下..为什么我的模块安装后直接用require找不到模块..必须加上绝对路径..是不是要写什么配置
回复 (6)
F
报错不知道是什么原因,路径的问题你可以看看这个应该就明白了 http://club.cnodejs.org/topic/4f41f516c643fe221005115b
我一般是在 ~/ 目录里执行 sudo npm install -pd 模块名 来安装
J
引用 feng013报错不知道是什么原因,路径的问题你可以看看这个应该就明白了 http://club.cnodejs.org/topic/4f41f516c643fe221005115b 我一般是在 / 目录里...
我是在/bin目录下安装的...不过我发现lib目录下也发现一个node-modules目录..下面有一些模块..不知道这个是不是默认的目录..但是直接在这个路径下安装好象也调不到模块.
J
引用 feng013报错不知道是什么原因,路径的问题你可以看看这个应该就明白了 http://club.cnodejs.org/topic/4f41f516c643fe221005115b 我一般是在 / 目录里...
谢谢你..放到配置好的目录里就木有问题了..但是还是那个错误.
R
io.listen不能是http 要是http.createServer
var http = require('http'), io = require('/usr/local/node/bin/node_modules/socket.io');
var app = http.createServer(function( request, response ){
response.writeHead( 200, {"Content-type": "text/html"});
response.end();
}).listen(80);
var socket = io.listen(app);
另外听80端口的话需要root权限
J
为什么我这边经常看不到 回复连接...想回人家一下都不行..
谢谢2楼的..我先试下...
J
谢谢2楼的...好象可以了..但是客户端搞了半天出问题了.
参与回复
登录后即可参与回复。登录