title: NodeJS as Websocket client using ws
body: <p>I need to send a message to a websocket server through request POST. The client is not a browser but a Node server.</p>
  
  <p>I'm new to websocket.</p>
  
  <p>When I run the code below.</p>
  
  <pre><code>var WebSocket = require("ws");
  const express = require("express");
  var app = express();
  
  const client = new WebSocket(process.env.URL);
  client.on("error", handleError);
  
  client.onopen = () =&gt; {
    client.send("Message From Client");
  };
  
  function handleError(error) {
    console.log(error);
  }
  
  app.get("/echo", async function (req, res) {
    client.once("connection", function connection(cli) {
      cli.send(msg);
      res.send("send");
    });
  });
  
  app.listen(3333, function () {
    console.log("Example app listening on port 3333!");
  });
  </code></pre>
  
  <p>It shows the error</p>
  
  <pre><code>Error: write EPROTO 19524:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
  
      at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16) {
    errno: 'EPROTO',
    code: 'EPROTO',
    syscall: 'write'
  }
  </code></pre>