2012-06-04 38 views
1

我安装了node_module connect来使用静态方法。这是我的代码:node + now.js + connect给我一个错误

var http = require('http'); 
var connect = require('connect'); 
var nowjs = require("now"); 
var app = connect(); 

app.use(connect.static('/var/www/www.domain.com/htdocs')); 

app.use(function(req, res){ 
    res.end(); 
}); 

http.createServer(app).listen(8001); 


var everyone = nowjs.initialize(http); 

但我得到一个错误:

[TypeError: Object #<Object> has no method 'listeners'] TypeError: Object #<Object> has no method 'listeners' 
    at Object.wrapServer (/home/chris/nowjs/node_modules/now/lib/fileServer.js:23:29) 
    at [object Object].initialize (/home/chris/nowjs/node_modules/now/lib/now.js:181:14) 
    at Object.<anonymous> (/home/chris/nowjs/multiroomchat_server.js:15:22) 
    at Module._compile (module.js:446:26) 
    at Object..js (module.js:464:10) 
    at Module.load (module.js:353:31) 
    at Function._load (module.js:311:12) 
    at Array.0 (module.js:484:10) 
    at EventEmitter._tickCallback (node.js:190:38) 

的哪些错误?

+1

这有帮助吗? 'var server = http.createServer(app).listen(8001); var everyone = nowjs.initialize(server);' –

+0

yes yes it!谢谢!请张贴它作为答案,所以我可以批准它:) – Chris

+0

一个下面的问题:它的工作正常与.html文件,但如果我打开本地主机:3000/test.php它给我test.php下载.. – Chris

回答

3

http变量是对http模块的引用,而不是创建的http服务。你需要把从createServer()传回来的变量传递给Now.js.幸运的是,listen()将它链接起来,你不必分手。

var server = http.createServer(app).listen(8001); 
var everyone = nowjs.initialize(server);