如何使用app.listen端口设置socket.io?

时间:2018-12-15 10:17:30

标签: node.js express socket.io mean-stack

所以我有这个server.js,但是我尝试了每种解决方案都可以运行到socket.io,但是当我从mongodb中插入值时,它并不能实时显示

var express     = require ('express');
var app         = express();
var port        = process.env.PORT || 8080;

app.listen(port, function(){
    console.log('Running the server on port ' + port);
});

我尝试了此操作,但不起作用

var express     = require ('express');
var app         = express();
var port        = process.env.PORT || 8080;
var io = require("socket.io")(port);


app.listen(io, function(){
    console.log('Running the server on port ' + port);
});

0 个答案:

没有答案