I am trying to use socket.io and express. Is it possible to initialize the socket inside routes/index.js in an express application?
I tried requiring app.js and listened on that, but it didn't work.
var app = require('../app.js');
var io = require('socket.io')(app);
If the above is not possible, how can I initialize the io variable inside app.js and then use it in index.js?
What I am trying to understand is how to modularize socket.io
Let's say that I have an website where two pages uses sockets. I don't want to put all code for both of them inside app.js.
Aucun commentaire:
Enregistrer un commentaire