title: Why is the variable undefined? - Node - ElectronJs
body: <p>I am creating an Electron app and I am trying to split my code in different scripts to make it more manageable; however, for some reason one of the variables in my script keeps returning undefined and I can't figure out why. I already checked similar questions here on SO, but did not find an answer.</p>
  
  <p>I have a file called windowManipulation.js and this is part of it:</p>
  
  <pre><code>let signInWindow;
  
  module.exports.createSignInWindow = () =&gt; {
      signInWindow = new BrowserWindow({
          show: false,
          width: 1500,
          height: 800,
          webPreferences: {
              nodeIntegration: true
          }
      });
  
      signInWindow.loadFile(`views/logIn.html`)
  
      signInWindow.once("ready-to-show", () =&gt; {
          signInWindow.show();
      });
  
      signInWindow.on("close", () =&gt; {
          signInWindow = null;
      });
  
      signInWindow.on('crashed', () =&gt; {
          app.relaunch();
          app.exit(0);
      })
  }
  
  module.exports.closeSignInWindow = () =&gt; {
          signInWindow.close();
          signInWindow = null;
  }
  </code></pre>
  
  <p>Now, when I call the function to create the window it creates it without a problem. But when I call the function to close it, it says that signInWindow is undefined.</p>
  
  <p>Why is it undefined if it was supposed to be set when the signInWindow was created? What am I doing wrong?</p>