A Node.js library for fetching JSON from URLs with disk caching. It updates the cache only when the ETag changes, and falls back to cached data if the endpoint is unreachable. Uses write-file-atomic for safe file writes. v1.6.3 requires Node >=0.8, ships TypeScript types, and supports both callbacks and Promises. Designed for reliability in offline or flaky network scenarios.
npm install fetch-json-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage with callbacks and promises, including forced update and cache clearing.
Ensure you are using Node >=0.8 and consider polyfilling Promise/async-await for older environments.
Use the promise-returning API (cache.get returns a Promise if no callback is provided).
Ensure the cache directory exists before creating the Cache instance: fs.mkdirSync('./cache', { recursive: true }).If your API does not return ETags, cache behavior may be suboptimal; consider using force: true to bypass cache.
When using force update, pass options as second argument: cache.get(url, { force: true }, callback).Run 'npm install fetch-json-cache' and verify it appears in node_modules.
Use: const Cache = require('fetch-json-cache'); const cache = new Cache('./path');Create the directory before instantiation: require('fs').mkdirSync('./cache', { recursive: true });