@abmsourav/localdb

LocalDB is a NodeJS CRUD api. It uses local file system for CRUD operation.

Usage no npm install needed!

<script type="module">
  import abmsouravLocaldb from 'https://cdn.skypack.dev/@abmsourav/localdb';
</script>

README

LocalDB

LocalDB is a NodeJS CRUD API. It uses local file system for CRUD operation. It's a promise based API.



Installation

npm i @abmsourav/localdb


API

GET localDB.get()

POST localDB.set(jsonObject)

UPDATE localDB.update(jsonObject, newValue)

DELETE localDB.remove(jsonObject)


Uses

const {localDB} = require('@abmsourav/localdb');
const ldb = localDB();

const data = {names: "Sourav", email: "keramotul.islam@gmail.com"};

// add new data
ldb.set(data)
    .catch( (err) => console.log(err) );

// get data from localDB
ldb.get()
    .then( (data) => console.log(data) ) // [ {name: 'Sourav', email: 'keramotul.islam@gmail.com'} ]
    .catch( (err) => console.log(err) );

// update data
ldb.update({name: "Sourav"}, "Abm Sourav") // args: 1. where update'll made, 2. new value
    .catch( err => console.log(err) );

// Delete data
ldb.remove({name: "Abm Sourav"})
    .catch( err => console.log(err) );

You can also add your own db file

Please note: It must be a json file.

const ldb = localDB('./db.json');

Promise Supports

ldb.set({"email": "keramotul.islam@gmail.com"})
    .then(() => ldb.update({"greetings": "Hello World"}, "Hello Universe"))
    .then( () =>  ldb.remove({"name": "ABM Sourav"}))
    .then( () =>  ldb.get().then(data => console.log(data)));


ldb.update({"name": "Sourav"}, "Abm Sourav")
    .then(() => ldb.remove({"greetings": "Hello Universe"}))