1

我安装了 node_module 连接以使用静态方法。这是我的代码:

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)

怎么了?

4

1 回答 1

3

http变量是对 http 模块的引用,而不是创建的 http 服务。您需要获取从 the 传回的变量createServer()并将其传递给 Now.js。谢天谢地listen(),您不必中断线路。

var server = http.createServer(app).listen(8001);
var everyone = nowjs.initialize(server);
于 2012-06-05T00:12:38.233 回答