Not A Real DB NPM Package

Introduction - Not a Real DB

 
It's a "fake" database NPM package that works as a database that allows you to store a data in JSON file. Install NPM package using below command. 
  1. npm i notarealdb  || yarn add notarealdb 
Official Package Link.
 
Benefits of notarealdb Package
  • It's a fake database, which is free
  • Use this database as small staging area of sample applications for clients to review
  • Easy to understand and simple integration
  • Operates with synchronous

How To Use It


Create a Datastore instance, where you want to store data, and then create an object of each collection of JSON file.

For example, let's create JSON files for students and courses so that you need to create files on ./data/students.json and ./data/courses.json files. Once files are saved you need to integrate into applications as below
  1. // Referenced 'notarealdb' package  
  2. const { DataStore } = require('notarealdb');  
  3.    
  4. // Referenced JSON files or database files    
  5. const store = new DataStore('./data');  
  6. const students = store.collection('students');  
  7. const courses = store.collection('course'); 
Performing CRUD operation using notarealdb package
  1. // Create new item will return auto generated ID in return  
  2. const id = courses.create({ coursename : 'NodeJs', createdDate : new Date().toLocaleString() });    // => 'XW449uPiN  
  3.   
  4. // Fetch list of all records from  collection  
  5. courses.list(); // => [{id: 'XW449uPiN', coursename : 'NodeJs', createdDate : "10/2/2021, 12:35:59 pm" }]  
  6.       
  7. // get single record from json file based on ID  
  8. courses.get('XW449uPiN'); // => {id: 'XW449uPiN', coursename : 'NodeJs', createdDate : "10/2/2021, 12:35:59 pm"}  
  9.    
  10. // update record from json file  
  11. courses.update({id: 'XW449uPiN', coursename : 'NodeJs Update', createdDate : new Date().toLocaleString()});  
  12.    
  13. // delete record from json file  
  14. courses.delete('XW449uPiN');     

Summary

 
This is a free NPM package which allows you to perform simple CRUD operations with a database of JSON file. Sometimes we face many issues whenever we deal with the client for a demo of applications. We cannot purchase any proper database environment for simple applications due to the cost of databases nowadays, so to reduce those issue this package allows you to develop simple CRUD based applications that we can show as an example. It's very very easy to integrate and utilize.