node.jsnode.js-connectnowjs-sockets

node+now.js+connect gives me an error


I installed the node_module connect to use the static method. This is my code:

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);

But I get an error:

[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)

Whats wrong?


Solution

  • The http variable is a reference to the http module, not the created http service. You need to take the variable passed back from the createServer() and pass that to Now.js. Thankfully listen() chains it and you don't have to break up the line.

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