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

node-json-file-storage

v1.1.0

Published

A simple, lightweight node.js file storage for JSON data

Downloads

40

Readme

Node JSON File Storage

npm GitHub Snyk Vulnerabilities for npm package npm npm Tests

A simple, lightweight node.js file storage for JSON data.

Installation

Download this project via Github and add it manually to your project or install the JSON File Storage npm / yarn package:

npm i node-json-file-storage / yarn add node-json-file-storage

How to Use / API

Create a new Store

// load lib...
const JSONFileStorage = require('node-json-file-storage'); // adjust the require path, if not installed via npm/yarn

// create store...
const file_uri = __dirname + "/your-storage-name.json";
const storage = new JSONFileStorage(file_uri);

Put

// content to save...
const obj_1 = 'some_content';
const obj_2 = {bar: 'baz'};

// save to file 
const id = storage.put(obj_1); // returns a random uuid 'id_1'

// save multiple items into the store (faster than calling put() twice)
const ids = storage.putBulk([obj_1, obj_2]); // returns an array of uuids: ['id_1', 'id_2']

A Note on the Use of IDs

You can use the storage in db manner (auto-id) const id = storage.put('your_content'); or key-value manner by wrapping your content in an object and providing your own keys in an id field storage.put({id:'your_key', 'your_content'}).

If you put an object with an id existing in the store, the existing and the new object will be merged, strings etc. will be replaced. An example: the new object {'id': {'foo': 1, 'bar': 2}} and the existing {'id': {'foo': 2, 'baz': 4}} will result in {'id': {'foo': 1, 'bar': 2, 'baz': 4}}.

Get (Everything)

// retrieve an item from the store
const obj = storage.get('id_1'); // returns the item or null

// retrieve multiple items from the store (again, its faster)
const objs = storage.getBulk(['id_1', 'id_2']); // returns an array of items found: ['some_content', {bar: 'baz'}]

// read the whole store
const everything = storage.all(); // returns a copy of the store: [{'id_1': 'some_content'}, 'id_2': {bar: 'baz'}}]

Remove (Everything)

// remove an item from store
const bool = storage.remove('id_1'); // returns if successfull
// or simply...
storage.remove('id_1');

// remove multiple items from the store (you know why...)
storage.removeBulk(['id_1', 'id_2']);

// clear the whole store
storage.clear();

Donate

If you like the project and it saved you a while of coding, spend me a coffee (or all of your savings) to keep me motivated: paypal.me