npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

for.db

v4.0.24

Published

Visual readable database module.

Downloads

138

Readme

ForDB Readable Database Module

What is ForDB?

ForDB is a human-readable database module designed for use with Node.js applications. One of its standout features is the ability to store data in either JSON-DB or YAML-DB formats. Unlike many other Node.js modules, ForDB allows you to manually edit and view the database content. You can access or create databases from any location, making it highly flexible for various use cases.

How Does ForDB Work?

When you use the ForDB module, it creates a dedicated database and continuously checks and updates it with the data you process. ForDB is compatible with any Node.js project, provided the Node.js version is 12 or higher.

You can configure ForDB to stop recording data when the database reaches a certain point. If needed, you can clear the JSON or YAML file and continue using the database.

Note:

This behavior applies only when you specifically configure the database to stop recording data. In all other cases, ForDB will continue to store data indefinitely.

What Can You Do with ForDB?

  • Delete data
  • Add data
  • Check if data exists
  • Retrieve all data
  • Create databases in custom locations
  • Access databases from any point within your project
  • Choose between YAML or JSON formats
  • Use mathematical methods with the database
  • Utilize finding methods (e.g., .includes | .startsWith)
  • Completely destroy the database
  • View data types

ForDB Installation

No additional setup is required to use ForDB. Simply install it in your project and start using it.

npm install for.db

Usage Examples

Below are examples of how to use the ForDB module:

Database Setup

const {
    JsonDatabase,
    YamlDatabase
} = require("for.db");

const db = new JsonDatabase({
  databasePath: "./databases/myJsonDatabase.json"
});

const yamlDB = new YamlDatabase({
  databasePath: "./databases/myYamlDatabase.yml"
});

Adding and Retrieving Data

// Data set | get

db.set("test", 1);
db.get("test");
db.fetch("test");

Checking for Existing Data

// Data exists

db.has("test");
db.exists("test");

Retrieving All Data

// Get all data

db.all(5); // Fetch the first 5 entries
db.all();  // Fetch all entries
db.fetchAll(5); // Fetch the first 5 entries
db.fetchAll();  // Fetch all entries

Converting to JSON

// To JSON

db.toJson(5); // Convert the first 5 entries to JSON
db.toJson();  // Convert all entries to JSON

Deleting Data

// Delete data

db.delete("test");
db.deleteAll();
db.findAndDelete((element, db) => {
    return element.ID.includes("test");
});

Getting Data Type

// Get data type

db.type("test"); // ---> number

Database Array Methods

// DB Array methods

db.push("testArray", 10);
db.pull("testArray", (element, index, array) => element < 10, true); // Multiple options = true (default is false)
db.valueArray(); // Get array of values
db.keyArray();   // Get array of keys

Database Math Methods

// DB Math methods

db.math("test", "*", 3); // Multiply the value by 3
db.add("test", 10);      // Add 10 to the value
db.substr("test", 5);    // Subtract 5 from the value

Database Finding Methods

// DB Finding methods

db.includes("tes");    // Check if any key includes "tes"
db.startsWith("t");    // Check if any key starts with "t"

Information

// Infos

console.log(db.size); // Log the size of the database
console.log(db.info); // Log the database info

Destroying the Database

// Destroy DB

db.destroy(); // Completely destroy the database

By following this guide, you can effectively utilize ForDB in your Node.js projects, taking advantage of its readability and flexibility.