persisted-json-object

0.2.0 • Public • Published

Persisted JSON objects for Node

This is an object that functions like a plain JavaScript object, but it saves itself to the file system after every change. Uses Proxy.

Usage

Use it just like a regular JavaScript object:

let jsonObject = require("persisted-json-object");

let obj = jsonObject({ file: "data.json" });

obj.foo = "boo";

obj.temporary = "soon to be deleted";
delete obj.temporary;

obj.grue = "you";

obj.coolNumbers = [420, 666, 69, 12];

After these changes, data.json will look like this (some formatting added):

{
  "foo": "boo",
  "grue": "you",
  "coolNumbers": [420, 666, 69, 12]
}

A few notes:

  • If data.json exists, it will load that data.
  • If data.json doesn't exist, it will be written as soon as you set a property.
  • Errors will be thrown if your object cannot be serialized as JSON.

Readme

Keywords

Package Sidebar

Install

npm i persisted-json-object

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

4.7 kB

Total Files

5

Last publish

Collaborators

  • evanhahn