Created
July 4, 2023 01:41
-
-
Save Paulo-Lopes-Estevao/e68704dc5fcbc35eb8161e6245bd6d7c to your computer and use it in GitHub Desktop.
Websocket node js client Authorization Bearer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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