I've successfully fetched one page of data but I need all of the data from the server into a single json file. The url is this: https://ticketwala.pk/api/backend/events/public?page=1
My code is:
const url = "https://ticketwala.pk/api/backend/events/public?page=1"
const data = fetch(url)
.then(response => response.json())
.then(data => {
const fs = require('fs')
fs.writeFile('test.json', JSON.stringify(data), function(err) {
if(err){
return console.log(err)
}
console.log("file was saved")
})
}).catch(error => {
console.error(error)
})
If I use a loop, how do I know where the execution should stop? Is a loop the best way to do this? I'm new to javascript.