Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonverse

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonverse

jsonVerse is a lightweight JSON-based database package for Node.js. It provides a simple interface to store, retrieve, and manage data using JSON files.

  • 1.0.13
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jsonVerse

jsonVerse is a lightweight JSON-based database package for Node.js. It provides a simple interface to store, retrieve, and manage data using JSON files.

Introduction

The jsonVerse package is a powerful utility designed to simplify the management of JSON data files within a designated folder. It offers methods for adding, editing, deleting, and retrieving data from JSON files. This wiki provides detailed examples and usage scenarios to help you effectively implement the jsonVerse package in your projects.

Installation

To begin using the jsonVerse package, you'll need to install it via npm. Open your terminal and run the following command:

npm install jsonverse

Usage

Import and Initialization

To get started, import the required modules, set up an Express router, and initialize the jsonVerse instance:

const express = require("express");
const app = express();
const jsonverse = require("jsonverse");

// Initialize the JSONDatabase instance
const db = new jsonverse("./path/to/your/data/folder");

Display All Data

You can display all the data from your website using the following code:

app.get("/", async (req, res) => {
  try {
    const allData = await db.getAllData();
    // ... (rendering logic)
  } catch (err) {
    // ... (error handling)
  }
});

Add Data

To add data, use the following code:

router.post("/add", async (req, res) => {
  try {
    const { dataName, name, social, rank, competition, date, edu } = req.body;
    const newData = {
      social,
      name,
      rank,
      competition,
      date,
      edu,
    };
    await db.addData(dataName, newData);
    // ... (redirect or response)
  } catch (err) {
    // ... (error handling)
  }
});

Get Data by ID

Retrieve data by its ID with this code:

router.get("/:id", async (req, res) => {
  const id = req.params.id;
  try {
    const result = await db.findDataById(id);
    if (result) {
      // ... (rendering logic)
    } else {
      // ... (not found logic)
    }
  } catch (err) {
    // ... (error handling)
  }
});

Delete Data by ID

Delete data by its ID using this code:

router.delete("/:id", async (req, res) => {
  const id = req.params.id;
  try {
    await db.deleteDataById(id);
    // ... (response or redirect)
  } catch (err) {
    // ... (error handling)
  }
});

Edit Data by ID

Edit existing data using this code:

app.post("/edit/:id", async (req, res) => {
  const id = req.params.id;
  const { name, social, rank, competition, date, edu } = req.body;
  try {
    const updatedData = {
      social,
      name,
      rank,
      competition,
      date,
      edu,
    };
    await db.editDataById(id, updatedData);
    // ... (response or redirect)
  } catch (err) {
    // ... (error handling)
  }
});

Conclusion

The jsonVerse package simplifies the management of JSON data files within a specified folder. With the provided examples and usage instructions, you'll be able to efficiently integrate the jsonVerse package into your projects to streamline data operations.

Keywords

FAQs

Package last updated on 31 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc