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.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
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.

Installation

To install jsonVerse, use the following command:

npm install jsonverse

Usage

// Import required modules and setup express router
const express = require("express");
const router = express.Router();
const jsonVerse = require("jsonVerse");
// Specify the data folder path
const dataFolderPath = path.join(__dirname, "../Data");

// Initialize the JSONDatabase instance
const db = new jsonVerse(dataFolderPath);
// Display all the website data
router.get("/", async (req, res) => {
  try {
    const allData = await db.getAllData(); // getAllData is used if you have multiple json files andd you want to show them all
    // ... (rendering logic)
  } catch (err) {
    // ... (error handling)
  }
});
// Add data
router.post("/add", async (req, res) => {
  try {
    const { dataName, name, social, rank, competition, date, edu } = req.body; // here you have to add the dataName which is where you want to save the data in the json files you have, here i store the name of the dataName from the UI (User interface - Front end) 

    // Generate a random unique ID
    // this is a package you have to install
    const uniqueID = uuid.v4();
    const newData = {
      id: uniqueID,
      social,
      name,
      rank,
      competition,
      date,
      edu,
    }; // whatever the data you want to receive from the front end form

    await db.addData(dataName, newData);
    // ... (redirect or response)
  } catch (err) {
    // ... (error handling)
  }
});
// Get data by ID
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
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
app.post("/edit/:id", async (req, res) => {
  const id = req.params.id;
  const { name, social, rank, competition, date, edu } = req.body;

  try {
    const existingData = await db.findDataById(id);

    const updatedData = {
      social,
      name,
      rank,
      competition,
      date,
      edu,
    }; // whatever the data you want to receive from the front end form

    await db.editDataById(id, updatedData)
    // ... (response or redirect)
  } catch (err) {
   // ... (error handling)
  }
});

FAQs

Package last updated on 27 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