Skip to content

Instantly share code, notes, and snippets.

@Paulo-Lopes-Estevao
Created July 4, 2023 01:41
Show Gist options
  • Save Paulo-Lopes-Estevao/e68704dc5fcbc35eb8161e6245bd6d7c to your computer and use it in GitHub Desktop.
Save Paulo-Lopes-Estevao/e68704dc5fcbc35eb8161e6245bd6d7c 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