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

fs-memory-store

v0.2.0

Published

Filesystem store with in-memory cache

Downloads

36

Readme

fs-memory-store Build status

Filesystem store with in-memory cache

This was built for usage with eight-track, an HTTP fixture library. It is designed for ease-of-access while debugging. By default, items will be stored to separate .json files in the folder.

Getting Started

Install the module with: npm install fs-memory-store

// Generate a store inside of `http-fixtures`
var Store = require('fs-memory-store');
var store = new Store(__dirname + '/http-fixtures');

// Save a value
store.set('hello', {world: true}, function (err) {
  // If there was an error, `err` will be it

  // We have created `http-fixtures/hello.json`
  /*
  {
    "world": true
  }
  */

  // Load the value
  store.get('hello', function (err, val) {
    // If there was an error, `err` will be it
    // Log our value
    console.log(val); /* {world: true} */
  });

  // Load an non-existent value
  store.get('wat', function (err, val) {
    // If there was an error, `err` will be it
    // Log our value
    console.log(val); /* null */
  });
});

Documentation

fs-memory-store returns Store as its module.exports.

Store(dir, options)

Constructor for a new store

  • dir String, Directory to generate our store inside of
  • options Object, Container for options/flags
    • ext String, Extension to save values under. By default, this is .json
    • stringify Function, Stringifier to pass values through when saving to disk
      • By default, this is JSON.stringify with an indenation of 2
    • parse Function, Parser to pass values through when loading from disk
      • By default, this is JSON.parse

Store#get(key, cb)

Retrieve an item from memory with a fallback to disk.

  • key String, Identifier to retrieve item by
  • cb Function, Error-first callback function to receive item value
    • Signature should be (err, val)
    • err Error|null, If there was an error, this will be it
    • val Mixed|null, If the value was found, this will be it. If it was not found, this will be null.

Store#set(key, val, cb)

Save an item to memory and disk

  • key String, Identifier to save item under
  • val Mixed, Value to save under the key
  • cb Function, Error-first callback function to handle errors
    • Signature should be (err)
    • err Error|null, If there was an error, this will be it

Store#delete(key, cb)

Delete an item from memory and disk

  • key String, Identifier to delete item under
  • cb Function, Error-first callback function to handle errors
    • Signature should be (err)
    • err Error|null, If there was an error, this will be it

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

License

Copyright (c) 2014 Todd Wolfson

Licensed under the MIT license.