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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@elang_muhammad/jsondb-node

v1.0.7

Published

A simple JSON database manager that allows you to interact with JSON files through a command-line interface, inspired by SQL-like commands.

Downloads

11

Readme

jsondb-node

A simple, file-based JSON database manager accessible from the command line. This tool allows you to perform CRUD (Create, Read, Update, Delete) operations on JSON files using an interactive REPL, with commands inspired by SQL.

Features

  • Interactive REPL: Manage your JSON data interactively.
  • SQL-like Commands: Use commands like .create, .insert, .update, .delete, and .show.
  • Tab Completion: Smart tab completion for commands, file paths, and table names.
  • No Dependencies: The core library works without any external Node.js modules.

Installation

To install jsondb-node globally, run the following command:

npm install @elang_muhammad/jsondb-node

Make sure you are in the jsondb-node directory when you run this command.

Usage

Once installed, you can start the interactive REPL by simply running:

jsondb

Or, you can directly open a JSON file:

jsondb /path/to/your/database.json

Example

$ jsondb

🌟 JsonDB >>> .build
📁 Enter database path (example: data/mydb.json): my_database.json
✅ Database 'my_database.json' created/opened successfully!
💡 Use '.create <table_name>' to create a new table

📦 [my_database.json] >>> .create users
✅ Table 'users' created successfully!

📦 [my_database.json] >>> .use users
✅ Successfully selected table 'users'!
💡 Use '.insert' to add data

📋 [users] >>> .insert
... (interactive prompt to add data) ...

📋 [users] >>> .show
... (displays data in the 'users' table) ...

Library Usage

In addition to the interactive REPL, you can use jsondb-node as a Node.js module in your projects.

Importing

You can import the JsonDB class into your JavaScript file like this:

import { JsonDB } from 'jsondb-node';
// Or using require
// const { JsonDB } = require('jsondb-node');

Example Usage

Here is a basic example of how to use the library:

import { JsonDB } from 'jsondb-node';

// 1. Initialize the database
const db = new JsonDB('my_database.json');

// 2. Create a table
db.createTable('users');

// 3. Insert data into the 'users' table
db.insertData('users', { id: 1, name: 'Alice', age: 30 });
db.insertData('users', { id: 2, name: 'Bob', age: 25 });

// 4. Get all data from the 'users' table
const users = db.getData('users');
console.log('All users:', users);
// Output: All users: [ { id: 1, name: 'Alice', age: 30 }, { id: 2, name: 'Bob', age: 25 } ]

// 5. Update data
// Update user where id is 1
db.updateData('users', (user) => user.id === 1, { id: 1, name: 'Alice Smith', age: 31 });

// 6. Delete data
// Delete user where age is 25
db.deleteData('users', (user) => user.age === 25);

// 7. Show the final data
console.log('Final users data:');
db.showData('users');
// Output:
// === Table: users ===
// Type: Array
// Length: 1
// Data: [
//   {
//     "id": 1,
//     "name": "Alice Smith",
//     "age": 31
//   }
// ]

API Reference

Here are the main methods available in the JsonDB class:

  • constructor(filePath): Initializes the database with the given JSON file path.

  • createTable(tableName, [initialData]): Creates a new table (a key in the JSON object).

    • tableName (string): The name of the table.
    • initialData (any): Optional initial data for the table. Defaults to an empty array [].
  • insertData(tableName, data): Adds data to a table. If the table is an array, it pushes the data. If it's an object, it merges the data.

    • tableName (string): The name of the table.
    • data (any): The data to be added.
  • updateData(tableName, [condition], newData): Updates data in a table.

    • tableName (string): The name of the table.
    • condition (function): A function that returns true for the item(s) to be updated. If null, the entire table content is replaced.
    • newData (any): The new data to replace the old data.
  • deleteData(tableName, [condition], [deleteAll]): Deletes data from a table.

    • tableName (string): The name of the table.
    • condition (function): A function that returns true for the item(s) to be deleted.
    • deleteAll (boolean): If true, all data in the table will be cleared.
  • getData([tableName]): Retrieves data.

    • tableName (string): The name of the table. If omitted, returns the entire database object.
  • listTables(): Returns an array of all table names.

  • tableExists(tableName): Checks if a table exists. Returns true or false.

  • showData([tableName]): Prints data to the console in a readable format. If tableName is omitted, it prints the entire database.

  • getTableInfo(tableName): Returns an object containing detailed information about a table, such as its name, type, and length.

Author

  • Elang Muhammad

License

This project is licensed under the MIT License.