App.js
var io = socket_io();
app.io = io;
var socket = require('./config/socketio')(io);
var routes = require('./app/routes/index');
socketio.js:
var config = require('./config');
module.exports = function(io){
io.on('connection', function (socket, next) {
socket.emit('hello', 'hello');
});
return io;
};
如何在不将套接字传递到每条路径的情况下使用socketio.js中的io?:
var socket = require('./config/socketio')(io);
var routes = require('./app/routes/index')(socket);