express.js中未处理的'错误'事件

时间:2016-07-01 08:39:51

标签: javascript node.js

var express = require('express');
var router = express.Router();

/* Socket.io */
var server = require("http").Server(express);  
var io = require("socket.io")(server);
server.listen(5000);
io.on('connection', function(client) {
  client.on('score_'+userId, function(data) {

  });
});

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;

socket.io块导致错误,但我不知道为什么。代码对我来说很好。

1 个答案:

答案 0 :(得分:1)

使用var server = require("http").createServer(express());代替var server = require("http").Server(express);