title: Send message to clients over WebSocket during express post request
body: <p>I'm currently trying to understand <code>NodeJS</code> and <code>express</code>. Currently I want to send a message to the connected clients to my <code>WebSocket</code> when a <code>POST</code> request comes in via <code>express</code>. How can I do this?</p>
  
  <p>This is my current code:</p>
  
  <pre><code>const WebSocket = require('ws').Server;
  const express = require('express');
  const bodyParser = require('body-parser');
  
  const app = express();
  const server = new WebSocket({
      server: app.listen(8181)
  });
  
  app.use(bodyParser.json());
  
  server.on('connection', socket =&gt; {
      socket.on('message', message =&gt; {
          console.log(`received from a client: ${message}`);
      });
      socket.send('Hello world!');
  });
  
  app.post('/', function (req, res) {
      console.log(req.body.name);
  
      res.sendStatus(200);
  });
  </code></pre>