I am writing some code for a program, but I'm not able to figure out how to assign the output of a fetch to a variable. Here's my code:
const fetch = require('node-fetch');
var totalNumOfPages;
fetch('https://api.hypixel.net/skyblock/auctions')
.then(res => res.json())
.then(totalPages => totalNumOfPages = totalPages)
console.log(totalNumOfPages)
The output is undefined, rather than the value of "totalPages" taken from the api. How can I assign the value of totalPages to the var totalNumOfPages.