title: How to automatically listener function on Socket IO
body: <p>Hello i want to try change icon notification,
  I'm already try chat with other user with socket io success,</p>
  <p>But i have a new problem when user want to know get new notification
  (in other menu or after login).</p>
  <p>when try have new notification, this function not working,
  i want when have new notification the id <strong>#notification_chat</strong>
  automatically add class <strong>.faa-ring</strong></p>
  <p>This is my file</p>
  <p>File <strong>server.js</strong></p>
  <pre><code>var app = require('express')();
  var http = require('http').createServer(app);
  var io = require('socket.io')(http, {
    cors: {
      methods: [&quot;GET&quot;, &quot;POST&quot;],
      credentials: true
    }
  });
  io.on('connection', function(socket){
  
    socket.on(&quot;reload-notif&quot;, function(){
      socket.broadcast.emit(&quot;reload-notif&quot;);
    });
  
    console.log('a user connected');
    socket.on('disconnect', function(){
      console.log('user disconnected');
    });
  });
  
  http.listen(3000, '0.0.0.0' ,function(){
    console.log('listening on *:3000');
  });
  </code></pre>
  <p>File <strong>index.php</strong></p>
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;style type=&quot;text/css&quot;&gt;
          .faa-ring {
              background-color: red;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;a href=&quot;http://localhost:2028/chat&quot;&gt;
        &lt;i id=&quot;notification_chat&quot; class=&quot;fa fa-comment animated&quot;&gt;&lt;/i&gt;
      &lt;/a&gt;
  
      &lt;!-- jQuery 3 --&gt;
      &lt;script src=&quot;http://localhost:2028/assets/vendor/jquery/dist/jquery.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Socket.IO --&gt;
      &lt;script src=&quot;localhost:/assets/vendor/socket.io/dist/socket.io.js&quot;&gt;&lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
          const socketIoAddress = &quot;http://localhost:3000&quot;;
          const socket = io(socketIoAddress);
  
          // i want if have new notification, this socket run automatically 
          socket.emit('reload-notif'); 
          socket.on('reload-notif', () =&gt; {
              notification_chat();
          });
  
          function notification_chat() {
              $.ajax({
                url: 'http://localhost:2028/chat/notification', 
                type: 'POST',
                dataType: &quot;html&quot;, 
                success: function(data) {
                   if(data==&quot;0&quot;){
                      $(&quot;#notification_chat&quot;).removeClass(&quot;faa-ring&quot;);
                   }
                   else {
                      $(&quot;#notification_chat&quot;).addClass(&quot;faa-ring&quot;);
                   }
                }
            });
          }
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Help me thank's</p>