title: Single instance of an object from a file in javascript
body: <p>This is creating 3 socket connections. There needs to be only 1 socket connection. This is probably fundamental javascript, but I am unable to figure out how to access the same instance of an object multiple times.</p>
  
  <pre><code>// File: socketConnection.js
  // -----------------------------------
  let socket = {};
  const socketConnection = {};
  socketConnection.connect = function() {
      if (!socket.connected) {
          socket = socketio();
      }
  };
  export default socketConnection;
  
  
  // File1
  // -----------------------------------
  import socketConnection from '../../socket/socketConnection';
  socketConnection.connect();
  
  
  // File2
  // -----------------------------------
  import socketConnection from '../../socket/socketConnection';
  socketConnection.connect();
  
  
  // File3
  // -----------------------------------
  import socketConnection from '../../socket/socketConnection';
  socketConnection.connect();
  </code></pre>
  
  <p>There are good reasons why it needs to be called from 3 separate files. But how can I ensure that there is only one <code>socket</code> that is referred to when checking <code>!socket.connected</code> ?</p>