Displays how long it took to fetch from API's.
npm install timefetcher
import timefetcher from 'timefetcher'
async function fetchData() {
try {
const url = 'https://api.spacexdata.com/v4/launches/upcoming';
const data = await timefetcher(url, 'milliseconds', '✨ The URL returned a result, nice!');
} catch (error) {
console.error('Failed to fetch data:', error);
}
}
fetchData();
Measures fetch time from the specified URL.
The URL to fetch the data from.
const url = 'https://api.spacexdata.com/v4/launches/upcoming';
Defines the unit in the default success message (by default, in milliseconds).
You can use the following:
milliseconds
seconds
minutes
hours
const data = await fetchtimer(url, 'seconds');
Defines a custom success message for when the URL returns a result.
const data = await fetchtimer(url, 'seconds', '✨ The URL returned a result, nice!');
Licensed under the MIT License.