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.
- npm i notarealdb || yarn add notarealdb
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
-
- const { DataStore } = require('notarealdb');
-
-
- const store = new DataStore('./data');
- const students = store.collection('students');
- const courses = store.collection('course');
Performing CRUD operation using notarealdb package
-
- const id = courses.create({ coursename : 'NodeJs', createdDate : new Date().toLocaleString() });
-
-
- courses.list();
-
-
- courses.get('XW449uPiN');
-
-
- courses.update({id: 'XW449uPiN', coursename : 'NodeJs Update', createdDate : new Date().toLocaleString()});
-
-
- 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.