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

light-json-db

v1.3.2

Published

Simple node.js database that uses JSON files and cache in under 400 lines

Downloads

4

Readme

light-json-db

Simple and small asynchronous json database for simple needs

Supports Folders and files containing JSON, names of any character set and any size - automatically parses and stringifies data

Works on Microsoft Windows and Linux distros (OSX has not been tested yet)

Additions

[v1.3.2]:dir function critical bug fix

v1.3.0

Cache now supports folders! (And files inside of folders that don't exist in disk yet) this fixed quite a lot of bugs

It is no longer possible to get a directory

v1.2.1

Files and folders can be diferenciated - the keys function now returns an object like this

{
	"myFile":{"type":"data"},
	"myOtherFile":{"type":"data"},
	"myFolder":{"type":"folder"}
	
}

data and folder are the only types for database entries currently.

Setup

npm i light-json-db

Example

const Database = require("light-json-db")




//Note: if you don't have a database folder you can set it up in an empty one 



(async ()=>{

	//This can be both /path/to/a/database/folder/ or
	//					 /path/to/a/database/folder
	//Altough it can't be /path/to/a/database/folder//

const db = new Database( "/path/to/a/database/folder"/*,{writeDelay:60000}*/)
//Makes database use the "/path/to/a/database/folder" path

//And will keep files written to or read in memory for 60 seconds
//(By default)
//

await db.set(["foo"],"bar");//Writes "bar" to file named "foo" in the database root

console.log(await db.get(["foo"]));
//bar (from cache)


await db.dir(["myDir"]);//Creates directory named myDir
await db.set(["myDir","fileInsideDir"],"baz"); //Creates "fileInsideDir" inside of it
console.log(await db.keys(["myDir"]));//Logs all files inside myDir
//{"fileInsideDir":{type:"data"}}

await db.remove(["foo"]);//Removes the foo file created at the start
await db.remove(["myDir"]);//Removes the myDir folder created above (and all files inside it)




//Paths are not separated by slashes (/), they are represented using Arrays of strings
//ie
// (db)/path/to/file is ["path","to","file"]


//Every directory can have as many characters as it needs and can use any characters Supported by JSON

//If you give db.set() an object value
//It will return the object when read()
//(it will parse and stringify it automatically)




})()

How it works

When you input any key as an array, it converts each element 
into its sha and separates them with `/`s.

Then, if you are creating a file, it adds that to a queue (sort of) and 
the file will eventually be written to. (with v1.2 that applies to folders as well)

and thats it. since it uses sha256 before writing, any filename of any length is 
accepted

  • Todo: [] Module to recover folder if index.json doesn't exist