///https://stackoverflow.com/questions/29334800/express-js-4-and-sockets-with-express-router
///USE THIS
var app = express();
app.io = require('socket.io')();
var routes = require('./routes/index')(app.io);
app.use('/', routes);
//Normal code here
//then at the bottom:
module.exports = function (io) {
//Socket.IO
io.on('connection', function (socket) {
console.log('User has connected to Index');
//ON Events
socket.on('admin', function () {
console.log('Successful Socket Test');
});
//End ON Events
});
return router;
};
/**
* Create HTTP server
*/
var server = http.createServer(app);
app.io.attach(server);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/