Hi,
I have a socket application with this file structure defined in app.js:
require("../chat/variables");
require("../chat/functions");
require("../chat/connect");
app.get('/', function (req, res, next) {
 res.sendFile(__dirname + '/index.html');
});
httpServer.listen(port, () => {
 console.log(`Socket.IO server running`);
});  
variables file looks like this:
// server
app = require("express")();
httpServer = require("https").createServer({},app);
io = require("socket.io")(httpServer, {      //socket server path
  path: "/"
});
functions file is something like this:
makesession = function(vdata) {   //store user data for this session
    if(socket) {
     socket.userid = vdata.userid;
     socket.username = vdata.name;
    }
   });
the file that performs the connection for each user looks like this:
io.on('connection', (socket) => {   //user connects to socket
   memberdata().then(v => {
    makesession(v);
   });
});   
but Im getting an error at the functions file saying that socket is not defined. Why is that? I thought it was enough with using the if condition so it only triggers after socket is defined.
Thank you.
 
    