key-file-storage
Simple key-value Node.js storage directly on file system, maps each key to JSON contents of a file.
I'll soon make a detailed readme for this module, but for now I just show you some examples :
- Initializing key-file storage :
var keyFileStorage = require("key-file-storage");
var kfs = keyFileStorage('/path/to/storage/directory');
var kfs = keyFileStorage();
- Setting a new value to a key :
var value = ...
kfs.set('key', value, function(err) {
if (err) { }
});
kfs.set('key', value).then(function() {
}, function(err) {
});
- Getting value of a key : (Value of a not existing key will be
null
)
kfs.get('key', function(err, value) {
if (err) { }
else { }
});
kfs.set('key').then(function(value) {
}, function(err) {
});
- Removing a key-file pair :
kfs.remove('key', function(err) {
if (err) { }
});
kfs.remove('key').then(function() {
}, function(err) {
});
- Clearing anything in the database folder :
kfs.clear(function(err) {
if (err) { }
});
kfs.clear().then(function() {
}, function(err) {
});
NOTE: undefined
is not supported as a savable value, but null
is. Saving a key with value undefined
is equivalent to remove it.
NOTE: Each key will map to a separate file (using the key itself as its relative path) so there is no need to load all the database file for any key access. Also, keys can be relative paths, e.g: data.json
, /my/key/01
or any/other/relative/path/to/a/file
.
NOTE: There is a built-in implemented cache, so accessing a certain key once again won't require file-system level operations.