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

@abibv/kval-dstore

v1.0.1

Published

A simple file based key-value data store that supports basic CRU

Downloads

8

Readme

kval-dstore

A simple file based key-value data store that supports basic CRUD operations in nodejs.

It creates a json file that can be used as a key-value database for learning purpose or even for micro-apps.

It provides five different API for accessing the key-value data store.

Initializing data store

new dstore(filename [,sizeLimit, initData]);

  • filename (String) - The file name with its path for the json file.
  • [optional] sizeLimit (String) - Specifies the sizeLimit in MegaByte (default is 1024 MB)
  • [optional] initData (JSON object) - Initial data to be stored at the time of file creation (default is empty json object {})
const dstore = require('@abibv/kval-dstore');

const store = new dstore('./dstore.json');
(or)
const store = new dstore(__dirname + '/dstore.json');

Write the data

store.write(object [,path]);

  • object (JSON object) - Data to be stored.
  • [optional] path (string) - Key path where the data should be placed (should be referred from the root) (default is the root of the json data '/')

write is an Asynchronous method which returns nothing.

var object = {
  name: 'myname',
  no: 123456789,
  timeSpent: {
    tech: '50%',
    music: '30%',
    sleep: '20%',
  }
};


//Write the data at the root

store.write(object)
  .then(() => { console.log('data written'); })
  .catch((error) => { console.log(error); });


//Write the data at the specified 

store.write(object, '/department/year/students/')
  .then(() => { console.log('data written'); })
  .catch((error) => { console.log(error); });

Read the data

store.read([path]);

  • [optional] path (String) - JSON key path from where the data should be read. (default is root '/')

If the path is not specified, then the whole data was read.

read is an Asynchronous method which returns the data read.

store.read('/department/year/students/')
  .then((data) => { console.log(data); })
  .catch((error) => { console.log(error); });

Update the data

store.update(data, key [,path]);

  • data (any) - data to be updated.
  • key (String) - JSON key whose value should be replaced (must be a Single key string).
  • [optional] path (String) - path of the key in the JSON object referred from the root '/'.

update is an Asynchronous method which returns nothing.

store.update({ misc: '10%' }, '/timeSpent')
  .then(() => { console.log('updated'); })
  .catch((err) => { console.log(err); });

Delete a Data

store.delete([path])

  • [optional] path (String path) - JSON key path from where the key-value pair should be deleted (default is root '/')

If no path is specified, then the whole data store with the file will be deleted

delete is an Asynchronous method which returns nothing.

store.delete('/timeSpent')
  .then(() => { console.log('timeSpent object deleted'); })
  .catch((error) => { console.log(error); });

Calculate data store size

store.calcFileSize()

calcFileSize is an Synchronous method which returns the size of the data store file in MegaBytes.

 console.log(store.calcFileSize());