Curious to know, are you using setinterval()
for your repeated REST request? You can perhaps make it simpler
async function getArrivalTime() {
// do your REST fetch here. You can use whatever library so for example I am using fetch from node-fetch here
const baseURL = `API`;
let res = await fetch(baseURL).catch((err) => {
throw new Error(`Error fetching content from ${baseURL}. ${err}`);
});
if (!res.ok) {
throw new Error(`Response status from ${baseURL}: ${res.status}`);
}
// manipulate your response
// let body = await res.text();
// Content body from github is base64 encoded
// return Base64.decode(JSON.parse(body).content);
}
setInterval(() => {
let content = await getArrivalTime();
// Console logs, write to file...etc
// MQTT publish to broker
}, 1000);
// Note this does it every 1 second!
and then just run your file node file.js