I want to fetch data from an API in regular interval. I wrote a script which is fetching data successfully but how to repeat this step for infinite time, so that I can fetch data in regular interval.
I want to fetch data in the interval of 1sec, what should I do?
const fetch = require('node-fetch')
const time = new Date()
function saveData(metrics) {
console.log(time.getSeconds())
console.log(metrics)
console.log(time.getSeconds())
}
const getData = () => {
fetch('http://example.com/api/v1')
.then(response => response.json())
.then(saveData)
.catch(err => console.error(err))
}
getData()