Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

key-file-storage

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-file-storage

Simple cached key-value Node.js storage directly on file system, maps each key to JSON contents of a file.

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by583.67%
Maintainers
1
Weekly downloads
 
Created
Source

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");

// To store files on disk
var kfs = keyFileStorage('/path/to/storage/directory');

// To store values on memory (useful for test)
var kfs = keyFileStorage();
  • Setting a new value to a key :
var value = ... // Any JSON-able object

// Callback form :
kfs.set('key', value, function(err) {
    if (err) { /*...*/ }
});

// Promise form :
kfs.set('key', value).then(function() {
    // Done!
}, function(err) {
    // Failed.
});
  • Getting value of a key : (Value of a not existing key will be null)
// Callback form :
kfs.get('key', function(err, value) {
    if (err) { /*...*/ }
    else { /* Do something with value ... */ }
});

// Promise form :
kfs.set('key').then(function(value) {
    // Done!
}, function(err) {
    // Failed.
});
  • Removing a key-file pair :
// Callback form :
kfs.remove('key', function(err) {
    if (err) { /*...*/ }
});

// Promise form :
kfs.remove('key').then(function() {
    // Done!
}, function(err) {
    // Failed.
});
  • Clearing anything in the database folder :
// Callback form :
kfs.clear(function(err) {
    if (err) { /*...*/ }
});

// Promise form :
kfs.clear().then(function() {
    // Done!
}, function(err) {
    // Failed.
});

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.

Keywords

FAQs

Package last updated on 20 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc