Get place visits and favorited count using NodeJS?

Hello, i’m trying to make a script that gets the Roblox Games API, and prints in the console the place visits and favorited count, but all i get in the console is this: Visits: [object Undefined]. Favorites: [object Undefined]. (Note that there’s no errors after printing this)
Here’s the script:

const APILink = "https://games.roblox.com/v1/games?universeIds=2736413683"
const fetch = require('node-fetch');
function getVisits() {
    let status; 
    fetch(APILink)
        .then((res) => { 
            status = res.status; 
            return res.json() 
        })
        .then((jsonData) => {
            return jsonData.visits;
        })
        .catch((err) => {
            console.error(err);
        });
}
function getFavorites() {
    let status; 
    fetch(APILink)
        .then((res) => { 
            status = res.status; 
            return res.json() 
        })
        .then((jsonData) => {
            return jsonData.favoritedCount;
        })
        .catch((err) => {
            console.error(err);
        });
}
console.log("Visits: " + toString(getVisits()) + ". Favorites: " + toString(getFavorites()) + ".")

I searched everywhere on how could i fix this, but didn’t find anything, so how can i fix this?

Try these:

return jsonData.data[0].visits
return jsonData.data[0].favoritedCount

It didn’t work, the same thing happened.

getVisits() does not return anything, neither does getFavorites()
You will need to use promises or async+await.

const fetch = require('node-fetch');
    const APILink = "https://games.roblox.com/v1/games?universeIds=2736413683"

function getVisits() {
    return fetch(APILink).then(res=>res.json()).then(jsonData=>jsonData.data[0].visits)
}
getVisits().then(visits=>console.log(`Visits: ${visits}`))
1 Like