- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
#Trying to get an API to work for Sydney Trains.
8 messages · Page 1 of 1 (latest)
async function loadTrainData() {
console.log('Fetching train data...');
try {
const response = await fetch('/api/trains');
if (!response.ok) {
const text = await response.text();
document.getElementById('train-info').innerText = `Error loading train data: ${text}`;
return;
}
const trains = await response.json();
console.log('Received train data:', trains);
const info = document.getElementById('train-info');
if (!trains.length) {
info.innerText = 'No realtime train updates currently.';
return;
}
info.innerHTML = '';
trains.slice(0, 10).forEach(train => {
const div = document.createElement('div');
div.style.marginBottom = '15px';
const tripId = train.tripId;
const route = train.routeId;
// Filter stops with arrival or departure time
const validStops = train.stopTimeUpdates.filter(stop => stop.departure !== null || stop.arrival !== null);
if (validStops.length === 0) {
div.innerHTML = `<strong>Trip ${tripId} (Route ${route}):</strong><br><em>No upcoming departures or arrivals available</em>`;
} else {
const stops = validStops.map(stop => {
const time = stop.departure || stop.arrival || 'No time available';
const type = stop.departure ? 'departs at' : 'arrives at';
return `${stop.stopId}: ${type} ${time}`;
}).join('<br>');
div.innerHTML = `<strong>Trip ${tripId} (Route ${route}):</strong><br>${stops}`;
}
info.appendChild(div);
});
} catch (err) {
document.getElementById('train-info').innerText = `Error fetching train data: ${err.message}`;
}
}
window.onload = loadTrainData;
script.js file ^
server.js file ^
How is any of this d.js related?
Its not. But where else could I ask? No where...
At least you could give some support?
#1081585952654360687 #useful-servers