npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fs-key-value

v1.2.0

Published

Key value data store using the filesystem

Readme

fs-key-value

npm version CI License: MIT

A simple key-value data store using only the filesystem. Uses POSIX file locking for safe operation in multi-process environments without the overhead of a separate database server.

Features

  • Simple key-value API (get, put, delete)
  • Both callback and async/await interfaces
  • File-based storage (values stored as JSON)
  • POSIX file locking for safe concurrent access
  • Works across multiple processes (via cluster, child_process, etc.)
  • No external database required

Requirements

  • Node.js >= 18.0.0
  • POSIX-compliant filesystem (Linux, macOS, etc.)

Installation

npm install fs-key-value

Quick Start

Using async/await

const FsKeyValue = require('fs-key-value');

const db = new FsKeyValue();
await db.openAsync('./mydb');

// Store a value
await db.putAsync('user:1', { name: 'Alice', age: 30 });

// Retrieve the value
const data = await db.getAsync('user:1');
console.log(data); // { name: 'Alice', age: 30 }

// Delete the value
await db.deleteAsync('user:1');

Using callbacks

var FsKeyValue = require('fs-key-value');

var db = new FsKeyValue('./mydb', function (err, db) {
  if (err) throw err;

  // Store a value
  db.put('user:1', { name: 'Alice', age: 30 }, function (err) {
    if (err) throw err;

    // Retrieve the value
    db.get('user:1', function (err, data) {
      if (err) throw err;
      console.log(data); // { name: 'Alice', age: 30 }

      // Delete the value
      db.delete('user:1', function (err) {
        if (err) throw err;
        console.log('Deleted!');
      });
    });
  });
});

API

new FsKeyValue([directory], [callback])

Creates a new key-value store instance.

  • directory (string, optional): Path to the storage directory
  • callback (function, optional): Called with (err, db) when initialization completes

db.open(directory, callback)

Initialize or reinitialize the store with a directory. Creates the directory if it doesn't exist.

  • directory (string): Path to the storage directory
  • callback (function): Called with (err, db) when complete

db.get(key, callback)

Retrieve a value by key.

  • key (string): The key to retrieve
  • callback (function): Called with (err, value). Value is undefined if key doesn't exist.

db.put(key, value, callback)

Store a value. The value is serialized to JSON.

  • key (string): The key to store
  • value (any): Any JSON-serializable value
  • callback (function): Called with (err) when complete

db.delete(key, callback)

Delete a key from the store.

  • key (string): The key to delete
  • callback (function): Called with (err) when complete

Async Methods

All methods are also available as async/Promise versions:

  • db.openAsync(directory)Promise<void>
  • db.getAsync(key)Promise<value | undefined>
  • db.putAsync(key, value)Promise<void>
  • db.deleteAsync(key)Promise<void>

Multi-Process Example

This example demonstrates safe concurrent access from multiple worker processes:

var cluster = require('cluster');
var FsKeyValue = require('fs-key-value');

if (cluster.isMaster) {
  // Fork 8 worker processes
  for (var i = 0; i < 8; i++) {
    cluster.fork();
  }
} else {
  var id = cluster.worker.id % 2;

  var mydb = new FsKeyValue('./mydb', function (err, db) {
    if (err) {
      return console.log(err);
    }

    db.put(
      'hoopla' + id,
      { msg: 'ballyhoo ' + cluster.worker.id },
      function (err) {
        if (err) {
          return console.log(cluster.worker.id + ' err ' + err);
        }

        db.get('hoopla' + id, function (err, data) {
          if (err) {
            return console.log(cluster.worker.id + ' err ' + err);
          }

          if (data != undefined) {
            console.log(data.msg);
          }

          db.delete('hoopla' + id);
          cluster.worker.kill();
        });
      }
    );
  });
}

How It Works

  • Each key is stored as a separate file in the specified directory
  • Values are serialized as JSON
  • Uses fs-ext for POSIX file locking (flock)
  • Shared locks for reads, exclusive locks for writes
  • Directory-level lock file (.lock) coordinates operations

License

MIT