Skip to content

Instantly share code, notes, and snippets.

@awsvpc
Forked from Paulo-Lopes-Estevao/index.js
Created January 5, 2024 11:05
Show Gist options
  • Save awsvpc/c6d28e12378344cf857d4c36e8683354 to your computer and use it in GitHub Desktop.
Save awsvpc/c6d28e12378344cf857d4c36e8683354 to your computer and use it in GitHub Desktop.
Websocket node js client Authorization Bearer
const WebSocket = require('websocket').w3cwebsocket;
var token = "key-token";
const socket = new WebSocket('ws://localhost:8000/ws', null, null, {
Authorization: `Bearer ${token}`
});
socket.onopen = () => {
console.log('WebSocket connection established');
};
socket.onmessage = (event) => {
console.log('WebSocket message received', event.data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment