Skip to content

Instantly share code, notes, and snippets.

@tfkhdyt
Last active January 24, 2024 00:06
Show Gist options
  • Save tfkhdyt/00cbcf8b458269e86471bc604b5eaf50 to your computer and use it in GitHub Desktop.
Save tfkhdyt/00cbcf8b458269e86471bc604b5eaf50 to your computer and use it in GitHub Desktop.
Node.js websocket example
const WebSocket = require("ws");
const ws = new WebSocket("wss://xapi.netovas.app/auth/inspect/ws");
ws.on("error", console.error);
ws.on("open", () => {
ws.send(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDY2MjE0MjAsImlkIjoxNzAzMDY5NDU4NTcyLCJyb2xlIjoicGFydG5lciJ9.m3h_XqTI-aGZPS4obnoKVfivDXy0cnVIQnoqQlqZNVA",
);
});
ws.on("message", (data) => {
const jsonData = JSON.parse(data);
console.log("Message from server:", jsonData);
});
@tfkhdyt
Copy link
Author

tfkhdyt commented Jan 24, 2024

Library ws ini hanya dapat digunakan di server. Untuk di client/browser bisa menggunakan Web API:

https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment