title: How to create a global HashMap in nodejs?
body: <p>Here is what my initial definitions are , all functions are in server.js one file</p>
  
  <pre><code>var HashMap = require('hashmap');
  global.user_to_Socket_Map = new HashMap();
  global.socket_to_user_Map = new HashMap();
  
  
  function makeOnline(username,socket)
  {
      socket.emit("test","hi");
  
      if(global.user_to_Socket_Map.has(username) != "true"){
          console.log("Setting callee socket of "+username
              + 'socket ' + socket);
          global.user_to_Socket_Map.set(username, socket);
          getSocket(username).emit('test','hi2')
          console.log("Setting callee socket of "+username);
          global.socket_to_user_Map.set(socket, username);
          global.userInCall_Map.set(username, "false");
      }
   }
  </code></pre>
  
  <p>and here is my getSocket function</p>
  
  <pre><code>function getSocket(username)
  {
      console.log("Getting callee socket of "+username);
      if(global.user_to_Socket_Map.has(username) == "true"){
          console.log("Actually Getting callee socket of "+username);
          return global.user_to_Socket_Map.get(username);
      }
  
  
  
  }
  </code></pre>
  
  <p>So , the error I get is <code>TypeError: Cannot call method 'emit' of undefined
   at line 25</code> , that is <code>getSocket(username).emit('test','hi2')</code> this function calling.</p>
  
  <p>But I have just set the value of the key username as a value in socket. But one line after it is returning an undefined. I have used the global keyword. But still getting the error.</p>