persistent-state
Super simple persistent states with JSON files.
const stateFile = '/path/to/file.json' { const state = stateFile await state state // undefined state // 123 state // 123 await state}) { const state = stateFile await state return state}
PersistentState(path)
Creates a persistent state instance.
path
- Path to the state JSON file.
PersistentState.load()
Loads the persistent state from file. Returns a promise.
PersistentState.get(name)
Gets a field's value.
PersistentState.set(name, value, save = false)
Sets a field's value. If save
is truthy, then this function returns a promise returned from .save()
.
PersistentState.save()
Saves the persistent state to file.