title: Send message from Node.js Server to Client via function call
body: <p>I want to send messages from my server to my client when a function is called. Using the code from <a href="https://stackoverflow.com/a/24232050/884275">this answer</a> messages can be successfully sent from Server to Client every second.</p>
  
  <p>I am building an application that runs node in the background, ideally I would like to be able to click a button that will call a function in the node server.js file which takes a parameter and sends that message to the client. The function in question would look like this</p>
  
  <pre><code>function sendToClient(message) {
      clients[0].emit('foo', msg);
  }
  </code></pre>
  
  <p>This would send the passed in message to the first client. How can I go about this?</p>
  
  <p>In terminal, after you run <code>node server.js</code> is there a way to call a function from the server file using terminal, this could be a possible solution if so.</p>