Skip to content

Instantly share code, notes, and snippets.

@suru-dissanaike
Last active April 16, 2021 12:35
Show Gist options
  • Save suru-dissanaike/a15f00882a98741d95e64d861b0f5c30 to your computer and use it in GitHub Desktop.
Save suru-dissanaike/a15f00882a98741d95e64d861b0f5c30 to your computer and use it in GitHub Desktop.
const WebSocket = require('ws');
// in order to handle self-signed certificates we need to turn off the validation
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const ws = new WebSocket('wss://localhost:8080');
ws.on('open', function open() {
ws.send('hello from client');
});
ws.on('message', function incoming(data) {
console.log(data);
ws.close(); // Done
});
ws.addEventListener('error', (err) => console.log(err.message));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment