title: How to trigger function from javascript websocket
body: <p>I am new to websocket. I am currently listening to a websocket in my node.js middleware application. Once I receive a message I have to store that message on database.</p>
  
  <pre><code>const ws = new WebSocket("ws://localhost:3000");
  
  ws.on("message", (event) =&gt; {
    console.log("connected to DB");
    testConnection();
  });
  </code></pre>
  
  <p>Whenever a new message is received the <code>testConnection</code> function should be triggered.</p>
  
  <pre><code>async function testConnection() {
    await sequelize.authenticate().then(() =&gt; {
      console.log("Connected to DB");
     })
     .catch((err) =&gt; {
      console.log(err);
    });
  };
  </code></pre>
  
  <p>I am trying to test connection for now.</p>
  
  <p>But whenever a new message is received the <code>testConnection</code> function is not getting called. </p>
  
  <p>I would like to know how to call a function when receiving a new message.</p>