How do I set up a socket connection with SSL?

  • 0
    Good afternoon, dears.
    I must say right away that I haven't worked with nodejs and sockets yet and I may not correctly formulate something in the question, thanks.

    In general, I got my hands on one laravel project that works on nodejs.
    It works like this, nodejs is launched on the server, which listens for client connections on a specific port.
    Everything works fine, without using ssl, but since the site works on SSL, this error occurs when the client connects to the server:
    WebSocket connection to 'wss://' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID

    Don't send it to Google, because I've been doing this for more than a day and nothing helps, or I'm doing something wrong.
    How did I try to get rid of this error? The one who gave me this project does not really understand himself and wrote the simplest instructions, which I followed. He wrote something like: you need to take the key and .crt from the certificate and write the paths to it in the .js script and everything should work. I did it all - it doesn't work.

    Below is the code:
    var privateKey = fs.readFileSync('ssl/', 'utf8');
    var certificate = fs.readFileSync('ssl/', 'utf8');
    var credentials = { key: privateKey, cert: certificate };
    var https = require('https');
    var httpsServer = https.createServer(credentials);
    var WebSocket = require('ws').Server;
    var wss = new WebSocket({
        server: httpsServer

    There are files in the ssl folder, the contents of them are readable - I checked all this using console.log, the server does not even start if one of these files contains an incorrect key or something else, that is, the data in these files is essentially valid. < br />
    Connected via telnet, the server responds, please help me solve this problem
    JavaScript Evan Whitney, Mar 18, 2020

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!