Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

node+now.js+connect gives me an error

node+now.js+connect gives me an error

Problem

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 # has no method 'listeners'] TypeError: 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. (/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?

Problem courtesy of: Chris

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);
Solution courtesy of: Ryan Olds

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

node+now.js+connect gives me an error

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×