Back

NodeJS Window not defined

  • 0
  • Self Hosted
  • Realtime
  • Web
Reality.exe
8 Mar, 2024, 17:09

I'm trying to subscribe to changes in a collection but im getting ReferenceError: window is not defined.

Here's the code i'm using

TypeScript
const { Client } = require("appwrite");

const client = new Client()
  .setEndpoint("https://aor.rxserver.net/v1")
  .setProject("gate-api");

client.subscribe("collections.gates.documents", (payload) => {
  console.log(payload);
});
TL;DR
Developer encountering 'ReferenceError: window is not defined' when attempting to subscribe to changes in a collection using NodeJS. The issue is that realtime/websocket connections are only supported in browser environments, not in NodeJS. Solution: Consider using a different method for real-time updates in a NodeJS environment.
Torsten Dittmann
8 Mar, 2024, 17:09

Currently Realtime/websocket connection are only supported in browser environments πŸ‘

Reality.exe
8 Mar, 2024, 17:10

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa shet

Torsten Dittmann
8 Mar, 2024, 17:10

whats your use case? πŸ™‚

Reality.exe
8 Mar, 2024, 17:12

I'm making a "Stargate Network" in a game called Resonite, I want to listen to changes for specific columns for when stargates are connecting to eachother so it plays the right animation in-game

Reality.exe
8 Mar, 2024, 17:13

It uses websockets to connect to the game itself

Reality.exe
8 Mar, 2024, 17:42

guess i'll just have to constantly check the state

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more