senchalabs/connect — Issue #483: Error: addListener only takes instances of Function
Author: goloroden
Created: 2012-02-26 17:04:45+00:00
State: open

What's wrong with the following code?

AFAICS it looks *exactly* like the code in the examples, but it throws an exception:

var middleware = function() {
return function(req, res, next) {
console.log('pre');
next();
console.log('post');
};
};

var connect = require('connect');
var http = require('http');

var app = connect()
.use(middleware())
.use(function(req, res) {
console.log('blablabla');
res.end('blablabla');
});
http.createServer(app).listen(3000); <== Throws an exception:

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: addListener only takes instances of Function
at Server. (events.js:101:11)
at new Server (http.js:1333:10)
at Object.createServer (http.js:1350:10)
at Object. (/home/golo/test/test.js:32:6)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)