QuickStorage
Simple key/value storage module with persistency on file system.
This module used to work in the browser with IndexedDB, more info can be found here https://github.com/BonneVoyager/quick-storage/tree/v1.4.0.
Installation
npm install --save quick-storage
Usage
QuickStorage
expects an argument - a path to store data in the file system (otherwise, it will throw).
This will create ${__dirname}/data
directory and store data in it. Each data key will be stored in separate file (key myKey
will be store in file ${__dirname}/data/myKey
). File content is stringified on write, and parsed on read.
API
myStorage
myStorage // true
myStorage // { "foo": "bar" }
myStorage // [ "foo" ]
myStorage
myStorageisReady // false before onReady callback, and true afterwards
myStorage
myStorage
const obj = foo: "bar" myStorage
Few tips
- please keep in mind that this module is intended to be used with small chunks of data (up to dozens of megabytes). All the data is stored in memory with
Map
cache object. - data is parsed between string and json. That means that this module works only with JSON objects.
- when you create
QuickStorage(__dirname + '/data')
, the script will try to find and read data associated with__dirname + '/data'
(read FS on the server). After it's read, storage object will callonReady
function. - you can use a callback as a second argument for
get
function to force read the data from the FS, instead ofMap
cache object.
Test
npm run test