filestore-json
Checks
Easily sync JSON objects of any shape with the filesystem.
Features
- Read & write to JSON files on a storage device without the need to interact with the filesystem.
- Persistant data between process restarts.
- Ability to determine age (ms since last write).
- Cache JSON responses from network requests.
- Automaticly updates internal value when JSON file is modified.
- Strong type internal value with type annotations.
Examples
Creating a store
import JSONStore from "filestore-json";
import path from "path";
const store = JSONStore.from(path.resolve("path/to/your/store.json"));
type Type = Record<string, any>;
const store = JSONStore.from<Type>(path.resolve("path/to/your/store.json"));
Reading & writing to the store
console.log(store.value);
store.value = { myObject: false };
console.log(store.value);
Creating a store with default values
const defaults = { defaultValue: true };
const store = JSONStore.from(path.resolve("path/to/your/store.json"), defaults);
console.log(store.value);
store.value = { myObject: false };
console.log(store.value);
Resetting a stores value back to the default
store.value = { myObject: false };
console.log(store.value);
store.clear();
console.log(store.value);
Getting the age of the store (ms since last write)
console.log(store.age);