Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/derhuerst/fetch-periodic-sync

fetch() a URL periodically, with caching & data-saving support.
https://github.com/derhuerst/fetch-periodic-sync

Last synced: 5 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# fetch-periodic-sync

**[`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) a URL periodically, with caching & data-saving support.**

[![npm version](https://img.shields.io/npm/v/fetch-periodic-sync.svg)](https://www.npmjs.com/package/fetch-periodic-sync)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/fetch-periodic-sync.svg)
![minimum Node.js version](https://img.shields.io/node/v/fetch-periodic-sync.svg)
[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)
[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)

## Installation

```shell
npm install fetch-periodic-sync
```

## Usage

```js
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](https://github.com/derhuerst/fetch-periodic-sync/issues).