I have a server in node.js based on Express. The modules name is www:
const http = require('http');
var app = require('../app');
server = http.createServer(app);
server.listen(config.serverPort);
module.exports = server;
In another module I want to define a socket.io connection. I am not able to pass the var server
to the other module. What is my mistake? If I run the code in one script everything works fine. So it looks like there is a problem passing the var server
to the other module.
var www = require('./www');
var io = require('socket.io')(www.server, {
cors: {
origin: '*',
methods: ["GET", "POST"]
}
});
io.on('connection', function(socket){
console.log('a user connected: ' + socket.id);
});
My failure looks like:
::ffff:192.168.178.11 - - [27/Feb/2021:17:24:53 +0000] "GET /socket.io/?EIO=4&transport=polling&t=NVaXOrG&b64=1 HTTP/1.1" - -
::ffff:192.168.178.11 - - [27/Feb/2021:17:24:58 +0000] "GET /socket.io/?EIO=4&transport=polling&t=NVaXQ3X&b64=1 HTTP/1.1" - -
::ffff:192.168.178.11 - - [27/Feb/2021:17:25:03 +0000] "GET /socket.io/?EIO=4&transport=polling&t=NVaXRHo&b64=1 HTTP/1.1" - -
::ffff:192.168.178.11 - - [27/Feb/2021:17:25:08 +0000] "GET /socket.io/?EIO=4&transport=polling&t=NVaXSW3&b64=1 HTTP/1.1" - -
Happy for some help! Thanks.