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

json-db-manager

v1.1.0

Published

Optimized JSON: Simplifies and Enhances Data Reading, Writing, and Management.

Downloads

11

Readme

json-db-manager

A simple json manager like "data base (DB)" local to your application, very advanced and malleable to use as you want.

  • Compatible with several EcmaScript (ES) technologies
  • Allowed to use "require()" and "import"

New features or changes

  • A new parameter in the class, which is for the creation of the JSON file that was defined in "Path" and that if no existing will be created a file.
  • "Request" events now have more items that return to their object.

Bugs fixed from the previous version

  • The "read" event was not responding.

How to use

const db = new JsonDB();

You can choose the spacing by placing the number of spaces inside the JsonDB class, the default being: 0

new JsonDB(2); // Espaçamento adicional

You can also choose between a json storing "base64" or "utf-8" which is the default. For "uft-8" do not enter a second parameter.

new JsonDB(0, "utf-8"); // Codificação opicional

The third parameter is responsible for management if your json file defined in "path" does not exist, can automatically create the file, being the standard: "false"

new JsonDB(0, "utf-8", true); // opicional para para criar arquivo.

Metodos

GET

path is a function that will provide you with the objects as soon as you enter the json file path

console.log(db.path("./dir").get())
// db.path("./dir").get("KeyExample")  Para procurar por um item especifico

Resultado exemplo

  {
    "KeyExample": {"velueExamples": [0, "1", [2, 2.5]]},
    "KeyExample1": 3,
  }

SET

Pass the "key" of your choice and the "value"

db.path("./dir").set("key", "value"); // Criando por parametro.
db.path("./dir").set({"key1": "value"}); // Formatação objeto.
db.path("./dir").set({"key2": "value", "key3": "value"}); // Formatação com objetos.

Resultado exemplo

  {
    "key": "value", // Criando por parametro.
    "key1": "value", // Formatação objeto.
    "key2": "value", // Formatação com objetos.
    "key3": "value", // Formatação com objetos.
  }

DELETE

Pass the "key" you want to delete

db.path("./dir").delete("keyExample");

Resultado exemplo

  {
    //keyExample is deleted
    "KeyExample1": 8,
  }

CLEAR

Delete all json and leave it ready for new values

db.path("./dir").clear();

Resultado exemplo

{} // Void

hostView

To create a server with your JSON file

  • The "port" method is responsible for listing the server port.
  • The "update" method allows when the page is reloaded to update the information based on the "json file".
  • The "update" is optional and the default is "false"
db.path("./test.json").hostView({ port: 3000, update: true })

"hostView" has two methods, "on" and "start".

The "on" method is responsible for performing manipulations on the "read" and "request" events.

While the "on" event is activated when the server is turned on, the "request" event is activated every time the server is accessed, such as when reloading the page or opening it for the first time.

Object made available by the event "read"

{
  "settings": {
    "port": "number",
    "update": "boolean"
  }
}
  • port - Refers to the door chosen by you to the server.
  • update - To indicate if the server will be updating the page.

Object made available by the event "request"

{
  "url": "string",
  "method": "string",
  "ip": "number" 
}
  • url - The route used to display "JSON".
  • method - The requisition method that was made on the server.
  • ip - It is the "IP" of the device that accessed the server on the JSON file route.

Object made available by the event "request"

url: string, method: string, ip: number

let num = 1;
const server = db.path("./test.json").hostView({ port: 3000, update: true })

server.on("read", (req) => {
    console.log(`Project started.\nPort: ${req.settings.port}\n`);
})

server.on("request", (req) => {
    console.log(`Project acessed: ${num} time\nURL acess: "${req.url}"\nAccessed by IP: ${req.ip}`);
    num++
})

server.start()//server initialization

Resultado exemplo

// Your browser | example URL: http://localhost:3000/data 

1 {
2   "KeyExample1": 8,
3 }

// Your logs | example

Project started.
Port: 3000

Project acessed: 1 time
URL acess: "/data"
Accessed by IP: 192.168.0.17

To connect other devices to the server, simply be on the same network and use the "IPv4" of your project machine along with the "port" listed.

Tip for "Windows" users:

  • Open "cmd" and run "ipconfig".
  • Look for the numbers in the line that says "IPv4 Address".

Resultado exemplo

# URL in your browser | example

http://192.168.0.22:3000