13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

express 3.x と socket.io を組み合わせて使う

Posted at

express 2.x までは socket.io と以下のように組み合わせて使うことができました。

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

app.listen(3000);

express Wiki の Migrating from 2.x to 3.x によれば、3.x から express.createServer() のかわりに express() を使うようになりましたが、express() の戻り値は http.Server ではありません。socket.io の listen()http.Server を引数にとるので、以下のように http.createServer() でラップしたものを使う必要があります。

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

server.listen(3000);
13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?