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

beepboop-persist

v1.0.0

Published

A javascript client to the BeepBoop Persist key/value store

Downloads

25

Readme

Sponsored by Beep Boop

Beep Boop Persist Key/Value Store JS Client

This is a node.js client for the Beep Boop Persist service. Though Persist only stores simple strings, this client will automatically JSON.stringify and JSON.parse objects passed as values.

If running on Beep Boop the below example should just work. If running outside of Beep Boop it will fall back to an in memory store. See further configuration options below.

var kv = require('beepboop-persist')()

kv.set('a key', 'the key, is water', function (err) {
  // handle error :)
  kv.get('a key', function (err, val) {
    // handle error :)
    // val should be 'the key, is water'

    kv.list(function (err, keys) {
      // handle error :)
      // keys should be ['a key']
      kv.del('a key', function (err) {
        // handle error :)
        // 'a key' should be deleted
      })
    })
  })
})

BeepBoopPersist([options])

Returns a Beep Boop Perist api:

  • options.serialize - defaults to true - all values will be run through JSON.stringify() and JSON.parse()
  • options.token - defaults to process.env.BEEPBOOP_TOKEN - auth token passed into environment by Beep Boop
  • options.url - defaults to process.env.BEEPBOOP_PERSIST_URL || process.env.BEEPBOOP_API_URL || 'https://beepboophq.com/api/v1' - service url passed into environment by Beep Boop
  • options.debug - defaults to false - if true then api calls and errors are logged.
  • options.logger - defaults to null - Should be an object w/ a debug and error function.
  • options.provider - defaults to null, acceptable values are "memory", "beepboop", or "fs" - this provides a way to override provider selection logic. If this isn't explicitly set, then the "beepboop" provider is used when both token and url are present. Otherwise the "memory" provider is used. "fs" can be used when running outside of Beep Boop to make data survive restarts. This provider shouldn't be used while running on Beep Boop though since the disks are ephemeral.
  • options.directory - defaults to .persist under module - Only used with the fs filesystem provider (meant for testing only) to control where data is stored.

.set(key, value, callback)

Set a value for a key. If value is not a string it will be JSON.stringify()'d if options.serialize is true

let obj = { foo: 'bar', baz: 1 }
kv.set('a key', obj, function (err) {
  // check for err
})

.get(key, callback)

Get a value for a key. If val is a string, it will be passed as such, otherwise it is JSON.parse()'d if options.serialize is true

kv.get('a key', function (err, val) {
  // check for err
})

.mget(keys, callback)

Get multiple values for a key.

kv.set('key1', 'string value', function (err) {})
kv.set('key2', { foo: 'bar' }, function (err) {})

let keys = ['key1', 'key1', 'non-existent-key']

kv.mget(keys, function (err, result) {
  // check for err

  // result = ['string value', { foo: 'bar' }, null]
})

.del(key, callback)

Delete a value at a key

kv.del('a key', function (err) {
  // check for err
})

.list(begins, callback)

List all keys:

kv.list(function (err, keys) {
  // check for err

  // keys is array of strings like ['key1', 'key2', 'baz3']
})

List keys that begin with a prefix:

// beings with 'key' for example
kv.list('key', function (err, keys) {
  // check for err

  // keys is array of strings like ['key1', 'key2']
})