Why does instantiating a class that relies on an API pull work outside routes but fail inside a POST route in Node.js?

I am using cPanel to deploy my Node.js application and working with CommonJS modules. My app uses a class, PastWeather, which fetches data from an external API.

When I instantiate the class outside any route, it works as expected, and I see the correct response in my terminal. For example:

try {
    const PastWeather = require('./pastWeather.js');
    const testInstance = new PastWeather('GHCND:USC00051547');
    console.log("Test instance created successfully:", testInstance);

    // Call a method from the class
    testInstance.parseData()
        .then(reply => {
            console.log("Parse Data executed successfully:", reply);
        })
        .catch(error => {
            console.error("Error during parseData execution:", error);
        });
} catch (error) {
    console.error("Error initializing PastWeather instance:", error);
}

However, when I move this logic inside a POST route like this:

app.post('/getLatandLang', async (req, res) => {
    try {
        const PastWeather = require('./pastWeather.js');
        const testInstance = new PastWeather('GHCND:USC00261327');
        console.log("Instance created successfully:", testInstance);

        res.json({
            message: "Instance created successfully",
            testInstance: testInstance.locationID,
        });
    } catch (error) {
        console.error("Error in /getLatandLang route:", error);
        res.status(500).json({
            message: "Error occurred while creating instance",
            error: error.message,
        });
    }
});

When I send a POST request to /getLatandLang, the request hangs and no response is sent. Additionally, the PastWeather instance seems to fail silently. I don’t see any errors in my logs.

I have tried taking the instantiation of the class that relies on the API pull outside of the POST request. When instantiated globally (outside any route), the class works as expected, and all subsequent data is retrieved correctly. However, when instantiated within the POST request, the request hangs, and the class fails to initialize or function properly, and my actual website usually times out without any error showing up.