object-to-file
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Build Status Weekly downloads

Object-to-file, JSON database

Featherweight writing and reading object to/from json files.

Installation

npm i object-to-file --save

Module usage

Try it out in RunKit

https://npm.runkit.com/object-to-file

var objectToFile = require("object-to-file")
var db = new objectToFile.default("testing-runkit");
db.push("Greeting", { Hello: "World"});
db.read("Greeting");

Docs

Creating database

Create a database named "database-name":

import Database from 'object-to-file';
var db = new Database("database-name");

// or...

var objectToFile = require("object-to-file");
var db = new objectToFile.default("database-name");

An empty database-name.json will be created.

Updating

Create "MyTesting" key and push an object to it:

db.push("MyTesting", { hello: "world" });

Reading

Single key

Get the object(s) of MyTesting key:

db.read("MyTesting");

object returned:

{ "hello": "world" }

Everything

Read entire file:

db.read(); 

object returned:

"MyTesting": {
    "hello": "world"
}

Deleting

Remove everything under "MyTesting" and the key:

db.delete("MyTesting");

Remove all data:

db.truncate();

Permanently remove the database (file):

db.unlink();

Test

ts-jest to run tests (not included in )

npm run test

Package Sidebar

Install

npm i object-to-file

Weekly Downloads

2

Version

2.0.1

License

ISC

Unpacked Size

4.78 kB

Total Files

4

Last publish

Collaborators

  • devkep