Getting socket.io v1.x.x to Work on Heroku

Many outdated tutorials will tell you that you need to add the below code to your server in order for socket.io code to work.

1
2
3
4
io.configure(function () {
    io.set("transports", ["xhr-polling"]);
    io.set("polling duration", 10);
});

However, in newer versions of socket.io (v1.x.x), the set() and configure() methods are deprecated, as outlined here, and they result in the error “io.configure is not a function”. Instead, you should pass in the settings when you initialize the instance, like this:

1
2
3
4
var io = require('socket.io')({
    "transports" : ["xhr-polling"],
    "polling duration" : 10
}).listen(server);

Also, in your client code you should use the “ws” protocol instead of “http” when trying to connect.

That should be all you need to get your app running!

Comments