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 🙏

© 2024 – Pkg Stats / Ryan Hefner

kvfs

v0.2.9

Published

Key-Value store based on the file system

Downloads

16

Readme

kvfs

kvfs is a Key-Value store based on the file system. It takes no time to set up, no infrastructure other than a file system, and lets you get started with your code real quick.

PLEASE NOTE that pre-1.0 this package might change its interface in a breaking manner between minor version bumps.

kvfs should not be used for serious production stuff, but is useful for getting started quickly. It uses the filesystem and is inherently undistributable. The goal is simple: get you started quick, let you decide on underlying layers later.

That said, here's some documentation and stuff...

Getting started

You need to decide on a path, relative to where you are running your application from, that will be your data store. In this example we will use a folder .data, but you could, for example, use /var/lib/.

Install the package from npm using your commandline:

npm install kvfs --save

Documentation

To create a new key-value store, simply pass the relative (to where you are running the app from) path for the store.

var kvfs = require("kvfs");
var myStore = kvfs(".myStore");

This will create a folder ".myStore" in your current working directory.

On myStore you can now call any of the supported functions, to work with your key-value store (below). In addition, the store is an event emitter, which lets you listen on changes to entries.

set

myStore.set(key, value, callback)
  • key string key to use for lookup
  • value any kind of standard JSON value (string, number, boolean, object, array). If it is not a standard value (a cyclic object, an object with functionality) kvfs will attempt to coerce it to JSON (basically JSON.stringify).
  • callback should take a single argument, error, in case something goes wrong.

get

myStore.get(key, callback)
  • key corresponding key: will retrieve the value that has been set for this key or fail
  • callback should take two arguments:
    • error in case something goes wrong
    • value the value retrieved

del

myStore.del(key, callback)
  • key the key to delete: the value will be erased
  • callback should take a single argument, error, in case something goes wrong.

list

myStore.list(prefix, callback)

This function works on collections. A collection consists of all entries with a shared prefix, ended with a forward slash /.

  • prefix the collection prefix to look for. For example, "hello" will match "hello/world", "hello/kitty", and even "hello/it/is/me", but not "hello-there". The prefix must be immediately followed by a forward slash /.
  • callback should take two arguments:
    • error in case something goes wrong
    • descendants all of the entries belonging to the collection

len

myStore.len(prefix, callback)

Like .list, but returning the number of children.

  • prefix the collection prefix to look for.
  • callback should take two arguments:
    • error in case something goes wrong
    • length (number) the number of entries in the collection

on

myStore.on(key, listener)
  • key key to listen for changes on. May use wildcards, for example "hello/**" will listen to changes for all entries in the hello collection (all descendants of "hello").
  • listener takes the exact key of the element that was changed.

Also supported:

  • once
  • onAny
  • ...

Contributing

Please feel free to open issues and Pull Requests on this repository if you have questions or suggestions :-)