[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 回复
报错不知道是什么原因,路径的问题你可以看看这个应该就明白了 http://club.cnodejs.org/topic/4f41f516c643fe221005115b
我一般是在 ~/ 目录里执行 sudo npm install -pd 模块名 来安装
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权限