-
-
Notifications
You must be signed in to change notification settings - Fork 1
1‐ Get Started
Welcome to jsonverse, a powerful data management package for Node.js! This guide will walk you through the essential steps to get started with jsonverse in your Node.js project.
To begin using jsonverse, you need to install it in your project. Open your terminal and run the following command:
npm install jsonverse
This command will download and install the jsonverse package in your project directory.
After installing jsonverse, you can import it into your Node.js application using the following code:
const Jsonverse = require("jsonverse");
This line imports the jsonverse package and makes its functionalities available in your application.
To use jsonverse, you need to initialize it with a data folder path. This folder will be used to store your data files. Here's how you can initialize jsonverse:
// Initialize the JSONDatabase instance
const db = new Jsonverse({
dataFolderPath: "./MyData", // data directory
logFolderPath: "./MyLogs", // logs directory
activateLogs: true, // to enable the logs set this value to true
});
In the code above, you create a new instance of jsonverse with the specified data folder path.
With jsonverse, you can easily create data stores and add data to them using the saveData
method. Here's an example:
const newData = { name: "John Doe", age: 30 };
jsonverse.saveData("userData", newData);
In this example, you create a new data store named 'userData' and add the 'newData' object to it.
You can read data from a data store using the readData
method. It returns an array of data objects. For example:
const userData = jsonverse.readData("userData");
console.log(userData);
The readData
method retrieves the data from the 'userData' store and logs it to the console.
To update data in a data store, you can use methods like editByID
or writeDataByFileName
. Here's an example using editByID
:
const updatedData = { age: 31 };
jsonverse.editByID("userData", "your-item-id", updatedData);
In this code, you update an item in the 'userData' store with the specified ID.
To remove data from a data store, you can use the delByID
method. For example:
jsonverse.delByID("userData", "your-item-id");
The delByID
method deletes an item with the specified ID from the 'userData' store.
These are the fundamental steps to get started with jsonverse. You can now create, read, update, and delete data in your Node.js application using this powerful package.