user3413838
user3413838

Reputation: 320

Node.js http.createServer throws TypeError: listener must be a function

index.js:

var koa = require('koa')
  , Primus = require('primus.io')
  , http = require('http')
  , app = koa()
  , server = http.createServer(app);

var primus = new Primus(server, { transformer: 'websockets', parser: 'JSON' });

primus.on('connection', function (spark) {
  spark.send('news', { hello: 'world' });
  spark.on('my other event', function (data) {
    console.log(data);
  });
});

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

server.listen(8080);
console.log('8080');

run: node --harmony index

and err: throw TypeError('listener must be a function');

Upvotes: 1

Views: 2287

Answers (2)

Johnny Hall
Johnny Hall

Reputation: 545

You need to change your code to do this:

server = http.createServer(app.callback())

Upvotes: 3

siuyong
siuyong

Reputation: 11

Try: add a star '*'

app.get('/',function*(next){})

Upvotes: 1

Related Questions