Socket.io + Express:快速声明错误

时间:2013-03-14 16:34:19

标签: javascript node.js sockets express socket.io

我要求:

//app.js Socket IO Test
var app = require('express').createServer(),
redis = require('socket.io/node_modules/redis'),
io = require('socket.io').listen(app);

我的错误:

Warning: express.createServer() is deprecated, express
applications no longer inherit from http.Server,
please use:
  var express = require("express");
  var app = express();

如何修改声明以避免此错误?我知道这种方法现在已经被Express弃用了,只是不确定它需要改为什么......

提前致谢!

1 个答案:

答案 0 :(得分:1)

只需将var app = require('express')。createServer()替换为:

var express = require("express");
var app = express();