Socket
Socket
Sign inDemoInstall

simple-json-store

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-json-store

Easily load and save data to JSON file


Version published
Weekly downloads
6
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Simple JSON Store

Easily load and save data to JSON file
Works synchronously so use as appropriate (CLI applications, simple writes)

Usage

const SimpleJsonStore = require('simple-json-store')

// Init a SimpleJsonStore instance with a file path
// and optionally some default values
const store = new JsonStore('./mystore.json', {foo: 'bar'});

store.set('awesome', true);

console.log(store.get('awesome'));
//=> true

console.log(store.get('foo'));
//=> bar

store.del('awesome');

console.log(store.get('awesome'));
//=> undefined

API

SimpleJsonStore(filePath, [defaults])

Create a new JsonStore instance store.

filePath

Type: string

File path to save JSON file to.

defaults

Type: object

Default content to init the store with.

store.set(key, value)

Set an item.

store.set(object)

Set multiple items at once.

store.get(key)

Get an item.

store.del(key)

Delete an item.

store.clear()

Delete all items.

store.all

Get all items as an object or replace the current config with an object:

store.all = {
	hello: 'world'
};

store.size

Get the item count.

store.path

Get the path to the JSON file. Can be used to show the user where the file is located or even better open it for them.

  • configstore - same thing but automatically sets up JSON save file for you
  • lowdb - simple JSON database with query capabilities
  • write-json-file - write JSON files atomically (async or sync)
  • steno - another option to write JSON files atomically

License

BSD license
Copyright Google

FAQs

Package last updated on 18 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc