Node app API caching not working after taking app live on heroku

Hello everyone. I’m having a bit of strange problem I can’t seem to figure out.

I have a web app for basketball scores that I’m working on here: https://www.stonscenter.com/

I’m using node to call the api for the news section every hour, then save the result of that call to a data.json file, then use that data to display the news. This is working fine on local host, but not since I deployed to heroku.

Now, the data either isn’t updating, or doesn’t show anything. I thought it might be because I was using the free tier for heroku, which makes the app sleep when it’s not in use, but now I’m using the hobby dyno, which doesn’t sleep, and I’m still having issues.

Sometimes the data doesn’t update and shows old data, and sometimes I get undefined in the app.js file that’s calling the data from the json file. When I check my azure account, it’s only showing 1 call to the api over the last 24 hours. So there must be an issue somewhere with how it’s being called or how it’s being written to the file.

Here’s the node code that I’m getting to call and cache the data:

//Require express framework
const express = require("express");
//Set express to app variable
const app = express();
const fs = require("fs");
const path = require("path");
const fetch = require("node-fetch");
const compression = require("compression");
require("dotenv").config();

app.use(compression());

//Set express to app variable
const PORT = process.env.PORT || 3000;

//Listen on port 3000 for server
app.listen(PORT, () => {
  console.log(`listening at ${PORT}`);
});

//Tell app which folder to use to show static on local server
app.use(express.static("public"));

//Tell app which folder to use to show static on local server
app.use(express.static(path.join(__dirname, "public")));

//////////////////////////////////////////

const api = process.env.API_KEY;
const requestOptions = {
  headers: {
    "Ocp-Apim-Subscription-Key": api,
  },
};

const api_url =
  "https://api.cognitive.microsoft.com/bing/v7.0/news/search?q=detroit+pistons";

const getData = () => {
  fetch(api_url, requestOptions)
    .then((response) => {
      return response.json();
    })
    .then((data) => {
      let newsData = data;
      //console.log(newsData);

      let dataFile = 'public/data.json'

      fs.writeFile(dataFile, JSON.stringify(newsData), function (err) {
        if(err) return console.log(err)
        return newsData
      })
      
    });
};

setInterval(() => getData(), 1000*60*60);

Is it something to do with how the data is saved to the json file? Or am I missing something about how the code runs on the server?

I noticed that when I run nodemon locally it restarts the server at the interval the getData function is set, which causes it to update properly. Is there something like this I have to install for production possibly?