Answer the question
In order to leave comments, you need to log in
How to connect socket.io?
In the app.js file (the main application file), I start listening to io and http.
There is a separate X module, which I included via require.
How to make io.emit from X?
That is, how to properly move io into a separate module, and then connect it to app and X
At the moment, app looks like this:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
var x = require('./x');
app.get('/', function(req, res){
res.sendFile(path.join(__dirname + '/public/index.html'));
});
http.listen(80, function(){
console.log('http.listen on 80');
});
Answer the question
In order to leave comments, you need to log in
var x = require('./x')(io);
// x.js
module.exports = function(io){
io.emit(......);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question