npm.io
1.1.5 • Published 4 years ago

fetch-periodic-sync

Licence
ISC
Version
1.1.5
Deps
1
Size
6 kB
Vulns
0
Weekly
0
Stars
6

fetch-periodic-sync

fetch() a URL periodically, with caching & data-saving support.

npm version ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

Installation

npm install fetch-periodic-sync

Usage

const syncViaPeriodicFetch = require('fetch-periodic-sync')

const synced = syncViaPeriodicFetch('https://wikipedia.org/', {
	interval: 5_000,
})

synced.on('error', (err) => {
	console.error('failed to refresh Wikipedia', err)
})
synced.on('change', (res) => {
	// res is a Fetch API Response
	// https://developer.mozilla.org/en-US/docs/Web/API/Response
	res.text().then(console.log)
})

Contributing

If you have a question or need support using fetch-periodic-sync, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.

Keywords