title: NODE.js & socket.io: how to check whether user is online/offline?
body: <p>I am making a chat application and I want to add an option to check whether user is online or offline. </p>
  
  <p>Assume I have an array of names (it's a current replacement for a future database), which is represented as 'all the users in chat ever existed'.</p>
  
  <pre><code>var users = {user1,user2,user3,...usern};
  </code></pre>
  
  <p>And also, assume I have some kind of html form for entering your username</p>
  
  <pre><code>&lt;p&gt;Enter your username&lt;/p&gt;
  &lt;p id="nickError"&gt;&lt;/p&gt;
  &lt;form id="setNick"&gt;
      &lt;input size="35" id="nickname" maxlength="25"&gt;&lt;/input&gt;
      &lt;button&gt;Chat!&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have logic and code to check whether the name from input area is in users array. Also, I have a basic chat in which you can talk globally or in private.</p>
  
  <p>Part of my server.js:</p>
  
  <pre><code>io.on('connection', function(socket){
  
      socket.on('new user',function(data,callback){
          if (data in users)
          {
          callback(false);
          } else{
              callback(true);
              socket.nickname = data;
              users[socket.nickname] = socket; 
              updateNicknames();
              io.emit('user joined', data);
          }
      });
  
  };
  </code></pre>
  
  <p>I wanted to make a function, named <code>updateNicknames()</code>, which will update the status of the user, so if a person with nickname which is in my user 'database' is connected, his status should be online, and vice versa.</p>