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

locdb

v1.1.0

Published

local Json db for NodeJS

Downloads

4

Readme

LocDB

LocDB is a local in-memory database module for NodeJS. It stores data in json files. LocDB is more reliable than you would think, since it does not constantly read from the json files, it only does that once you initialize the module, after that it is stored in memory and only written to the json files when updated.

Installation

Use the package manager npm to install LocDB.

npm i locdb

Usage

initialize the module

var Locdb = require('locdb');
var database = new LocDB('/path/to/directory');

retrieve, define or update and remove data.

//Your data is stored as an Object or Array (based on what you stored in your json file.), so you can treat it just like any javascript Array or Object.
//All databases are stored within .db

console.log(database.db.databaseName.someKey); //undefined

database.db.databaseName.someKey = 'value';
console.log(database.db.databaseName.someKey); //'value'

database.db.databaseName.someKey = 'otherValue';
console.log(database.db.databaseName.someKey); //'otherValue'

remove database.db.databaseName.someKey;
console.log(database.db.databaseName.someKey); //undefined

setUpdateInterval(Number: interval): Change the interval (milliseconds) in which the json files are update for changes. Default is 500ms. (half a second)

database.setUpdateInterval(500);

exists(String: db, [OPTIONAL] Boolean: file): Check if a database is registered or if the JSON file for the database exists.

//db is registered and file exists.
database.exists('databaseName') //true
database.exists('databaseName', true) //true

//db is registered but file is missing.
database.exists('databaseName') //true
database.exists('databaseName', true) //false

//db is note registered but file exists.
database.exists('databaseName') //false
database.exists('databaseName', true) //true

//db is not registered and file is missing.
database.exists('databaseName') //false
database.exists('databaseName', true) //false

register(String: db): Register a new database. If a JSON file for the database already exists, it won't be overwritten.

database.register('otherDatabase'); //won't return anything.

purge(String: db): Removes a database, you will have to make a backup yourself.

database.purge('otherDatabase'); //won't return anything.

log(String: msg): system function, puts out a message in the console and log file.

database.log('Log message');

config.json: stores configuration and a list of databases.

{
    "updateInterval": 500,
    "list": [
        "example"
    ]
}

Directory structure:

database_directory/
├───files
│   └───example.json
├───logs
│   └───date.locdb.log
└───config.json

Contributing

If you want to make an addition to the project, please make a pull request or for major changes, open an issue.

License

MPL-2.0