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

jdb_net

v0.0.1

Published

A powerful JSON database with server and client Side.

Downloads

7

Readme

jDB Net

Hello, welcome to the documentation of jDB Net. This module is focused on making an efficient database with real time connection. Area | Quick Description ------------ | ------------- Introduction | Have a basic Idea of the module. Structure | Have an idea of how the database looks. Getting Started | Get started using the module. Server Set-up | How to set-up the Server. Client Set-up | How to set-up the Client. Usage | How to use the Module. Examples | Examples using this Module.

Introduction

This module have two sides. The server side that will hold the database, listen and validate requests. and the client side that will send requests to get, add, or delete data. There are permissions based on keys the server makes (or you). This permissions include read (Read the data), write (Add items, change their value), and manage (Delete whole rows and add news). And you can use the same computer as a server and client.

Structure

"collection": {
    "item": "value"
}

Structure the JSON code below is a valid in this database. There are collections. Inside those collections there are items that cointains values.

collection => item => your info
// Example can Be
user => yaxeldragon => subscription => premium

// It supports JSON so you can add as much as you want.

Is fine if you don't get this now. In the practice you will understand it more.

Getting Started

To start using this database type the following in your console

npm install jdb_net

Wait until installed. Then import the module in your project by typing the following in your project

const jDB_Net = require('jdb_net');

Server Set-up

To set up the server is very easy. First construct the client like this

// Imports
const jDB_Net = require('jdb_net');
// Set-up the Server
const server = new jDB_Net.server({
    verbose: true, // Shows ALL Activity. (optional) (default: false)
});
  • Note : The JSON inside the constructor is totally optional. doing new jDB_Net.server(); would work, and have default values.

Then make the server listen for requests like this

server.listen(8080); // 8080: Is the PORT

Once you run this code it will give you a LOGIN KEY with default read: true, write: true, manage: false. You can make more going to etc/keys.json file and following the template.

  • Note : Make sure you have READ, and WRITE, and the IP of the machine you are running the server on.

Client Set-up

To set up the client it is slightly more complicated, and you need the IP, of server, and PORT, and LOGIN KEY. In this example the IP will be 127.0.0.1, the port will be 8080, and the key will be jdb (Not Recommended)

First construct the client like this

// Imports
const jDB_Net = require('jdb_net');
// Set-up the Client
const client = new jDB_Net.client('127.0.0.1:8080', 'jdb', {
    verbose: false // Shows ALL Activity. (optional) (default: false)
});
  • Note : The JSON inside the constructor is totally optional. doing new jDB_Net.client('127.0.0.1:8080', 'jdb'); would work, and have default values.

Then connect by doing

client.connect().then(() => {
    // All your code here.
    // (jDB is made so it waits for the server to connect to execute this.)
    [ ... ]
});

Usage

Command | Action ------------ | ------------- client.createCollection('collection'); | Creates a Collection. client.collectionExists('collection'); | Checks if a collection Exists. client.createItem('collection', 'item/s'); | Creates an Item inside a Collection. client.fetch('collection'); | Returns items inside a Collection. client.setItem('collection', 'item', 'value/s') | Sets a value to an existing Item.

Create Collection

client.connect().then(() => {                // Connect
    client.createCollection('collection');   // Create Collection
});

Simply creates a new Collection.

  • Needed Permissions :
    • Manage

Collection Exists

client.connect().then(() => {                // Connect
    client.collectionExists('collection').then(exists => {
        if ( exists == true ){
            console.log('Collection Exists') // Logs "Collection Exists"
        } else {
            console.log('Collection Doesn\'t Exists') // Logs "Collection Doesn't Exists" 
        }
    });
});

Checks if a collection Exists

  • Needed Permissions :
    • Read

Create Item

client.connect().then(() => {                           // Connect
    client.createItem('collection', 'item');            // Add a single Item
                  // OR
    client.createItem('collection', ['item', 'itemB]'); // Add multiple Items
});

Adds an item inside a collection.

  • Needed Permissions :
    • Write

Fetch

client.connect().then(() => {                           // Connect
    client.fetch('collection').then(data => {
        console.log(data);
        // If there are ITEMS you can do :
        console.log(data.item);
    });
});

Looks for all items inside a collection and return it as JSON

  • Needed Permissions :
    • Read

Set Item

client.connect().then(() => {        // Connect

    client.setItem('collection', 'item', 'value');

        // OR to expand more the Possibilities

    client.setItem('collection', 'item', {
        subitem: 'another value, Wow!'
    });
    
});

Set a value to an existing item. (It creates It as well)

  • Needed Permissions :
    • Write

Examples

Creating and Displaying Data

client.connect().then(() => {
    client.collectionExists('users').then(exists => {      // Checks if Collection Exists
        if (exists == true) {                              // ---------------------------
            client.createItem('users', '001');             // Create Items '001' Item in 'users' collection.
            client.setItem('users', '001', {               // Set values to '001' item in 'users' collection.
                plan: 'premium',                           // |  This value
                expires: '12/12/2012'                      // |_ And this value
            });                                            // ---------------------------
            client.fetch('users').then((users) => {        // Fetch all items in 'users' Collection.
                console.log(users['001'].plan);            // Logs "premium"
            });
        }
    });
});