B Seven
B Seven

Reputation: 45943

How to get started with socket.io?

Installed Node.js and socketio io (using npm). Node Hello World works.

Created app.js with the following line:

var io = require('socket.io')();

node node app.js throws exception:

io_test.js:1
ts, require, module, __filename, __dirname) { var io = require('socket.io')();
                                                                       ^
TypeError: object is not a function

How to fix?

OSX 10.7.5. Node.js 0.8.18.

Upvotes: 2

Views: 537

Answers (1)

Dhaivat Pandya
Dhaivat Pandya

Reputation: 6536

Replace that line with

var io = require('socket.io').listen(8080);

Basically, if you read the error description, the require('socket.io') is returning an object, not a function that you can call. If you look at the example code on the socket.io website, you can see that you can call listen() on the object returned. So, you could also write it like this:

var sockio = require('socket.io')
var io = sockio.listen(8080)

Upvotes: 7

Related Questions