Perseverant
An asynchronous, persistent, localForage inspired, filesystem based storage solution for NodeJS.
Concept
Each key will be stored as regular file with optionally encrypted serialized data.
By default, everything is kept super simple so whatever value will be saved as JSON.
It is possible to create a new instance with a different name, folder, encryption or serialization.
API
Following the meta description of the API.
const perseverant = ;// or import perseverant from 'perseverant'; // by default, the name of the storage is 'global' but// it is highly suggested to use your own project name insteadconst storage = perseverant:Perseverant // or ...const storage = perseverant:Perseverant // retrieve a key (read key file)storage:Promise<value || null> // store a key (write key file)storage:Promise<value> // remove a key (unlink key file)storage:Promise // clear all keys for the named storage (rm -rf folder and its files)// WARNING: if you call this on global name, it'll clean it allstorageclearcallback:Promise // returns the length of keys, from 0 to Nstoragelength:Promise<length> // returns all keysstorage:Promise<keys>
Things to consider
This project is not a database replacement, neither a secure way to store credentials, passwords, or any relevant data if you do not provide at least a password.
// insecure!const storage = ; // secure \o/const storage = ;
By default, everything is indeed stored as plain JSON, and in a location any other software can reach.
The goal of this project is to provide, specially to NodeJS CLI, a way to persist data in any kind of device.
Technically speaking
- each key is converted into its base64 or encrypted counterpart, and its value stored via
JSON.stringify
- if you provide your own
serializer
, you can also store recursive data or buffers and binaries, currently not supported in core (to keep it simple)