julian
julian

Reputation: 4714

socket.io don't support express3?

I started to learn socket.io and express3 but I found that when I do this -

var app = require('express').createServer()
var io = require('socket.io').listen(app);

app.listen(8080);

It writes to the console that express.createServer() is deprecated.

I googled about it but couldn't find any answers for that..what should I do?
Maybe I should downgrade express or something?

Upvotes: 0

Views: 66

Answers (2)

VeXii
VeXii

Reputation: 3109

lokking at thisyou need to change the var app = require('express').createServer()

var express = require('express')
  , app = express()
  , io = require('socket.io').listen(app);

Upvotes: 0

David Weldon
David Weldon

Reputation: 64342

Have a close look at the documentation. You'll see that there is a key difference between using socket.io in the section: "Using with the Express 3 web framework" vs "Using with the Express web framework". The example they give is:

var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('socket.io').listen(server);

server.listen(80);

Just follow that pattern and you'll be all set.

Upvotes: 1

Related Questions