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

jsondb-client

v1.1.0

Published

const db = require('jsondb');

Downloads

8

Readme

Here’s the updated README with the correct database name jsondb-yu03:


jsondb-client

jsondb-client is a server-based JSON database package designed for easy and secure CRUD operations using API requests. The database can be hosted anywhere securely with limits and custom authentication. The UI for the client is under development using Electron.js.

Overview

jsondb-client provides a simple and efficient way to interact with JSON databases similar to traditional MongoDB, but using the jsondb-yu03 server. This package allows you to manage your databases securely and with custom authentication, enabling you to host and manage your data effectively.

Note: The server-side operations are private and protected to prevent theft or unauthorized access. Ensure that your server configurations and credentials are kept secure to prevent any potential misuse.

Installation

Install via npm:

npm install jsondb-client

Usage

Import and Setup

const dbClient = require("jsondb-client");

const db = dbClient.setConnection({
  server: 'https://jsondb-yu03.onrender.com',
  username: 'testuser.com',
  password: '370149ecaf812899',
  database: 'jsondb-yu03'
});

const collection = db.Collection('fun');

Methods

create(data)

Creates a new document in the specified collection.

Example:

const result = await collection.create({ name: "John Doe", age: 30 });
console.log(result);

find(query)

Finds all documents matching the query.

Example:

const results = await collection.find({ age: { $gt: 20 } });
console.log(results);

findOne(query)

Finds a single document matching the query.

Example:

const result = await collection.findOne({ name: "John Doe" });
console.log(result);

findById(id)

Finds a document by its unique ID.

Example:

const result = await collection.findById("12345");
console.log(result);

save(data)

Creates or updates a document based on the provided data.

Example:

const result = await collection.save({ _id: "12345", name: "Jane Doe" });
console.log(result);

update(id, data)

Updates a document by its ID.

Example:

const result = await collection.update("12345", { age: 31 });
console.log(result);

updateOne(query, data)

Updates a single document matching the query.

Example:

const result = await collection.updateOne({ name: "John Doe" }, { age: 31 });
console.log(result);

updateMany(query, data)

Updates multiple documents matching the query.

Example:

const result = await collection.updateMany({ age: { $lt: 30 } }, { active: false });
console.log(result);

findByIdAndUpdate(id, data)

Finds a document by ID and updates it.

Example:

const result = await collection.findByIdAndUpdate("12345", { age: 31 });
console.log(result);

findOneAndUpdate(query, data)

Finds a single document matching the query and updates it.

Example:

const result = await collection.findOneAndUpdate({ name: "John Doe" }, { age: 31 });
console.log(result);

deleteOne(query)

Deletes a single document matching the query.

Example:

const result = await collection.deleteOne({ name: "John Doe" });
console.log(result);

deleteMany(query)

Deletes multiple documents matching the query.

Example:

const result = await collection.deleteMany({ age: { $lt: 30 } });
console.log(result);

findByIdAndDelete(id)

Finds a document by ID and deletes it.

Example:

const result = await collection.findByIdAndDelete("12345");
console.log(result);

findOneAndDelete(query)

Finds a single document matching the query and deletes it.

Example:

const result = await collection.findOneAndDelete({ name: "John Doe" });
console.log(result);

countDocuments(query)

Counts the number of documents matching the query.

Example:

const count = await collection.countDocuments({ active: true });
console.log(count);

distinct(field, query)

Finds distinct values for a specified field.

Example:

const values = await collection.distinct("age", { active: true });
console.log(values);

aggregate(pipeline)

Performs an aggregation operation.

Example:

const results = await collection.aggregate([{ $match: { active: true } }]);
console.log(results);

populate(path, query)

Populates a field by joining related data.

Example:

const result = await collection.populate("user", { active: true });
console.log(result);

exec(command, params)

Executes a custom command with parameters.

Example:

const result = await collection.exec("customCommand", { param1: "value1" });
console.log(result);

Additional Operations

Delete User

To delete a user, make a DELETE request to the /delete-user endpoint.

Request:

DELETE /delete-user
Content-Type: application/json

Body:

{
  "username": "user_to_delete"
}

Response:

{
  "message": "User deleted successfully"
}

Error Response:

{
  "message": "User not found"
}

Delete a Collection

To delete a collection, make a DELETE request to the /:dbName/:collectionName/delete-collection endpoint.

Request:

DELETE /:dbName/:collectionName/delete-collection

URL Parameters:

  • dbName: The name of the database.
  • collectionName: The name of the collection to delete.

Response:

{
  "message": "Collection 'collectionName' deleted successfully"
}

Error Response:

{
  "message": "Collection not found"
}

Delete a Database

To delete a database, make a DELETE request to the /delete-db/:dbName endpoint.

Request:

DELETE /delete-db/:dbName

URL Parameters:

  • dbName: The name of the database to delete.

Response:

{
  "message": "Database 'dbName' deleted successfully"
}

Error Response:

{
  "message": "Database not found"
}

Authentication and Setup

Creating New Credentials

To create new credentials, use the following curl command:

curl --location 'https://jsondb-yu03.onrender.com/register' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic bWFub2pnb3dkYWJyODkuY29tOmZmNzkwNTU1Zjk3YTZkNzc=' \
--data '{
   "email": "testuser.com"
}'

Response:

{
    "message": "User registered successfully",
    "username": "testuser.com",
    "password": "370149ecaf812899"
}

Creating a Database

To create a database, use the following curl command:

curl --location 'https://jsondb-yu03.onrender.com/add-database' \
--header 'Authorization: Basic dGVzdHVzZXIuY29tOjM3MDE0OWVjYWY4MTI4OTk=' \
--header 'Content-Type: application/json' \
--data '{
    "database":"jsondb-yu03"
}'

Response:

{
    "message": "Database added successfully",
    "databases": [
        "jsondb-yu03"
    ]
}

Creating a Collection

To create a collection, use the following curl command:

curl --location --request POST 'https://jsondb-yu03.onrender.com/jsondb-yu03/testcollection' \
--header 'Authorization: Basic dGVzdHVzZXIuY29tOjM3MDE0OWVjYWY4MTI4OTk=' \
--header 'Content-Type: application/json'

Response:

{
    "message": "Collection created successfully",
    "collection": "testcollection"
}

License

MIT : [email protected]


Feel free to make any additional adjustments or add more details as needed!