title: Javascript app to receive event on server to run another function visible by clients
body: <p>I want to make a web application that can receive an event from a client that changes the running function on the server.</p>
  <p>I think socket.io on a simple node app is the best way to start for now. In the future, I would like to permit multiple clients to call the function running on the server, while the other clients also view the changes being performed by other clients.</p>
  <p>The web app runs using a simple html page with a js file. It runs a function that loops. This function is a simple call to load a gif file on loop. This is already done and works fine on the browser console.</p>
  <pre><code>
  &lt;script type=&quot;text/javascript&quot;&gt;
  
  function sleep (time) {
    return new Promise((resolve) =&gt; setTimeout(resolve, time));
  }
  
      function changeImage(a) {
          document.getElementById(&quot;myImg&quot;).src= a;
          sleep(5000).then(() =&gt; {
          // Do something after the sleep!
          document.getElementById(&quot;myImg&quot;).src = &quot;img.gif&quot;;
          });     
      }
  &lt;/script&gt;
  
  </code></pre>
  <p>The HTML page simply can respond to events like this:</p>
  <pre><code>&lt;img id=&quot;myImg&quot; src=&quot;image.gif&quot; onclick='changeImage(&quot;image2.gif&quot;)'&gt;
  </code></pre>
  <p>I can call changeImage from the browser console. How can I expose this function to be remotely called by a client?</p>