title: publish message to web socket from route controller _ express + nodejs + webSocket
body: <p>I want to know is it possible access to ws instance from router controller level?</p>
  <p>this is my entrypoint :</p>
  <pre><code>// app.js
  // .... app configs
  const server = createServer(app);
  
  const websocket = new WebSocketServer({ httpServer: server });
  
  websocket.on(&quot;request&quot;, (request) =&gt; {
    let connection = request.accept(null, request.origin);
  
    connection.on(&quot;message&quot;, (message) =&gt; {
      connection.send(&quot;message&quot;);
      console.log(message);
    });
    connection.on(&quot;close&quot;, () =&gt; console.log(&quot;client closed&quot;));
  
    return connection
  
  });
  </code></pre>
  <p>I did some modification here in request object for accessing ws instance in every request object:</p>
  <pre><code>app.use((req, res, next) =&gt; {
    req.ws = websocket;
    next();
  });
  </code></pre>
  <p>so I want to know how can I publish messages with :</p>
  <pre><code>req.ws.send({message: &quot;hi&quot;}) 
  </code></pre>
  <p>I tried this trick with socket-io . but here I cannot access to ws.send() function.</p>